Last active
December 24, 2015 20:38
-
-
Save jnv/6858759 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# should return 3rd letter of text\n", | |
"# in argument, if doesn't exists return `nil`\n", | |
"def third_elem(thing)\n", | |
" if thing.length < 3\n", | |
" nil\n", | |
" else\n", | |
" thing[2]\n", | |
" end\n", | |
"end\n", | |
"# O'rly?" | |
], | |
"language": "ruby", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"thing = \"oi\"\n", | |
"thing[2]" | |
], | |
"language": "ruby", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "subslide" | |
} | |
}, | |
"outputs": [], | |
"prompt_number": 3 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"arr = ['sugar', 'spice']\n", | |
"arr[2]" | |
], | |
"language": "ruby", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "subslide" | |
} | |
}, | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"source": [ | |
"Do The Simplest Thing That Could Possibly Work" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"def reverse_arg(thing)\n", | |
" thing = thing.class == String ? thing.to_s.reverse : thing.to_a.reverse\n", | |
"end " | |
], | |
"language": "ruby", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"outputs": [], | |
"prompt_number": 6 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"def reverse_arg(thing)\n", | |
" thing.reverse\n", | |
"end " | |
], | |
"language": "ruby", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "fragment" | |
} | |
}, | |
"outputs": [], | |
"prompt_number": 7 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"def reverse_arg(thing)\n", | |
" if thing.respond_to? :reverse\n", | |
" thing.reverse\n", | |
" else\n", | |
" throw ArgumentError.new(\"Gimme something reversable!\")\n", | |
" end\n", | |
"end\n", | |
"reverse_arg({})" | |
], | |
"language": "ruby", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "subslide" | |
} | |
}, | |
"outputs": [ | |
{ | |
"ename": "ArgumentError", | |
"evalue": "uncaught throw #<ArgumentError: Gimme something reversable!>", | |
"output_type": "pyerr", | |
"traceback": [ | |
"\u001b[31mArgumentError\u001b[0m: uncaught throw #<ArgumentError: Gimme something reversable!>", | |
"\u001b[37m/home/j/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/jnv-iruby-0.0.1/lib/iruby/kernel.rb:67:in `throw'\u001b[0m", | |
"\u001b[37m/home/j/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/jnv-iruby-0.0.1/lib/iruby/kernel.rb:67:in `reverse_arg'\u001b[0m", | |
"\u001b[37m/home/j/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/jnv-iruby-0.0.1/lib/iruby/kernel.rb:70:in `initialize'\u001b[0m", | |
"\u001b[37m/home/j/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/jnv-iruby-0.0.1/lib/iruby/kernel.rb:147:in `eval'\u001b[0m", | |
"\u001b[37m/home/j/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/jnv-iruby-0.0.1/lib/iruby/kernel.rb:147:in `execute_request'\u001b[0m", | |
"\u001b[37m/home/j/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/jnv-iruby-0.0.1/lib/iruby/kernel.rb:207:in `start'\u001b[0m", | |
"\u001b[37m/home/j/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/jnv-iruby-0.0.1/bin/iruby_kernel:72:in `start_kernel!'\u001b[0m", | |
"\u001b[37m/home/j/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/jnv-iruby-0.0.1/bin/iruby_kernel:92:in `<top (required)>'\u001b[0m", | |
"\u001b[37m/home/j/.rbenv/versions/2.0.0-p247/bin/iruby_kernel:23:in `load'\u001b[0m", | |
"\u001b[37m/home/j/.rbenv/versions/2.0.0-p247/bin/iruby_kernel:23:in `<main>'\u001b[0m" | |
] | |
} | |
], | |
"prompt_number": 9 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 2, | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"source": [ | |
"Constructors" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"arr = Array.new\n", | |
"hsh = Hash.new\n", | |
"\n", | |
"p arr, hsh" | |
], | |
"language": "ruby", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "fragment" | |
} | |
}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"[]" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"{}" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 1, | |
"text": [ | |
"[[], {}]" | |
] | |
} | |
], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"arr = []\n", | |
"hsh = {}\n", | |
"\n", | |
"p arr, hsh" | |
], | |
"language": "ruby", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "fragment" | |
} | |
}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"[]" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"{}" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 2, | |
"text": [ | |
"[[], {}]" | |
] | |
} | |
], | |
"prompt_number": 2 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"hsh = {}\n", | |
"p hsh[:a]" | |
], | |
"language": "ruby", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "fragment" | |
} | |
}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"nil" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n" | |
] | |
} | |
], | |
"prompt_number": 3 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"hsh = Hash.new(0)\n", | |
"p hsh[:a]" | |
], | |
"language": "ruby", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "fragment" | |
} | |
}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"0" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 4, | |
"text": [ | |
"0" | |
] | |
} | |
], | |
"prompt_number": 4 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "-" | |
} | |
}, | |
"source": [ | |
"http://ruby-doc.org/core-2.0.0/Hash.html#method-c-new" | |
] | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 2, | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"source": [ | |
"Odd? Even?" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# Not Ruby enough\n", | |
"index = 1\n", | |
"index % 2" | |
], | |
"language": "ruby", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "-" | |
} | |
}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 5, | |
"text": [ | |
"1" | |
] | |
} | |
], | |
"prompt_number": 5 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# Better\n", | |
"index = 1\n", | |
"index.odd?" | |
], | |
"language": "ruby", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "-" | |
} | |
}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 6, | |
"text": [ | |
"true" | |
] | |
} | |
], | |
"prompt_number": 6 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 2, | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"source": [ | |
"Increment" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"#i = nil\n", | |
"i ||= 0\n", | |
"i += 1" | |
], | |
"language": "ruby", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "subslide" | |
} | |
}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 7, | |
"text": [ | |
"1" | |
] | |
} | |
], | |
"prompt_number": 7 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 2, | |
"metadata": {}, | |
"source": [ | |
"String Replacement: `sub`, `gsub`" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"word = \"!Hello? ^_^\"\n", | |
"# Worst\n", | |
"word = word.sub '!', ''\n", | |
"word = word.sub '?', ''\n", | |
"word = word.sub '^', ''\n", | |
"word = word.sub '_', ''" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 8, | |
"text": [ | |
"Hello ^" | |
] | |
} | |
], | |
"prompt_number": 8 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"word = \"!Hello? ^_^\"\n", | |
"# Still pretty bad\n", | |
"word.sub! '!', ''\n", | |
"word.sub! '?', ''\n", | |
"word.sub! '^', ''\n", | |
"word.sub! '_', ''" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 9, | |
"text": [ | |
"Hello ^" | |
] | |
} | |
], | |
"prompt_number": 9 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"word = \"!Hello? ^_^\"\n", | |
"# Better\n", | |
"word.gsub /[!\\?\\^_]/, ''" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 10, | |
"text": [ | |
"Hello " | |
] | |
} | |
], | |
"prompt_number": 10 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"word = \"!Hello? ^_^\"\n", | |
"# Smart\n", | |
"word.gsub /[^a-zA-Z ]/, ''" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 11, | |
"text": [ | |
"Hello " | |
] | |
} | |
], | |
"prompt_number": 11 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"word = \"!Hello? ^_^\"\n", | |
"# Effin' smart\n", | |
"word.gsub /[\\W_ ]/, ''" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 12, | |
"text": [ | |
"Hello" | |
] | |
} | |
], | |
"prompt_number": 12 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 2, | |
"metadata": {}, | |
"source": [ | |
"If / Then" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"i_had_a_tail = true\n", | |
"if(i_had_a_tail) then\n", | |
" \"I'd own the night\"\n", | |
"end" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 13, | |
"text": [ | |
"I'd own the night" | |
] | |
} | |
], | |
"prompt_number": 13 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"> Never use then for multi-line `if`/`unless`.\n", | |
">\n", | |
"> \u2014 [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide#syntax)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"if(i_had_a_tail) then \"I'd own the night\" end # Okay" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 14, | |
"text": [ | |
"I'd own the night" | |
] | |
} | |
], | |
"prompt_number": 14 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# Better\n", | |
"if i_had_a_tail\n", | |
" \"I'd swat the flies\"\n", | |
"end" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 15, | |
"text": [ | |
"I'd swat the flies" | |
] | |
} | |
], | |
"prompt_number": 15 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": [ | |
"Unless" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"if !i_had_a_tail\n", | |
" \"I'd swat the flies\"\n", | |
"end" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 16 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"unless i_had_a_tail\n", | |
" \"I'd swat the flies\"\n", | |
"end" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 17 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 2, | |
"metadata": {}, | |
"source": [ | |
"Each / For" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"arr = ['nothing', 'beer', 'wine', 'cider']\n", | |
"for i in 0..(arr.length-1)\n", | |
" puts \"#{i} bottles of #{arr[i]}\"\n", | |
"end" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"0 bottles of nothing\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"1 bottles of beer\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"2 bottles of wine\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"3 bottles of cider\n" | |
] | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 18, | |
"text": [ | |
"0..3" | |
] | |
} | |
], | |
"prompt_number": 18 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"for i in 0...arr.length\n", | |
" puts \"#{i} bottles of #{arr[i]}\"\n", | |
"end" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"0 bottles of nothing\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"1 bottles of beer\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"2 bottles of wine\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"3 bottles of cider\n" | |
] | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 19, | |
"text": [ | |
"0...4" | |
] | |
} | |
], | |
"prompt_number": 19 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"> Never use `for`, unless you know exactly why. Most of the time iterators should be used instead. \n", | |
">\n", | |
"> \u2014 [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide#syntax)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"arr.each_with_index do |container, count|\n", | |
" puts \"#{count} bottles of #{container}\"\n", | |
"end" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"0 bottles of nothing\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"1 bottles of beer\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"2 bottles of wine\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"3 bottles of cider\n" | |
] | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 20, | |
"text": [ | |
"[\"nothing\", \"beer\", \"wine\", \"cider\"]" | |
] | |
} | |
], | |
"prompt_number": 20 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"arr = ['nothing', 'beer', 'wine', 'cider']\n", | |
"arr.each_with_index do |container, count|\n", | |
" next if count.even?\n", | |
" puts \"#{count} bottles of #{container}\"\n", | |
"end" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"1 bottles of beer\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"3 bottles of cider\n" | |
] | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 21, | |
"text": [ | |
"[\"nothing\", \"beer\", \"wine\", \"cider\"]" | |
] | |
} | |
], | |
"prompt_number": 21 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 2, | |
"metadata": {}, | |
"source": [ | |
"Style" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"[Use the Guide!](https://github.com/bbatsov/ruby-style-guide)" | |
] | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": [ | |
"snake_case for variables and methods" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"myArray = [] # meh.\n", | |
"my_array = [] # yay!" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 22, | |
"text": [ | |
"[]" | |
] | |
} | |
], | |
"prompt_number": 22 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": [ | |
"Blocks" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"> Prefer `{...}` over `do...end` for **single-line blocks**.<br>\n", | |
"> Avoid using `{...}` for **multi-line blocks** (multiline chaining is always ugly).\n", | |
">\n", | |
"> \u2014 [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide#syntax)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# Ugly!\n", | |
"File.open(\"testfile\",\"w\") { |file|\n", | |
" file << \"hello\\n\"\n", | |
" file << \"world\"\n", | |
"}" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 23, | |
"text": [ | |
"#<File:0x007fc47b50eff0>" | |
] | |
} | |
], | |
"prompt_number": 23 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"File.open(\"testfile\",\"w\") do |file|\n", | |
" file << \"hello\\n\"\n", | |
" file << \"world\"\n", | |
"end" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 24, | |
"text": [ | |
"#<File:0x007fc47b4fcff8>" | |
] | |
} | |
], | |
"prompt_number": 24 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"names = ['Bozhidar', 'Steve', 'Sarah']\n", | |
"names.each { |name| puts name.upcase }" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"BOZHIDAR\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"STEVE\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"SARAH\n" | |
] | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 25, | |
"text": [ | |
"[\"Bozhidar\", \"Steve\", \"Sarah\"]" | |
] | |
} | |
], | |
"prompt_number": 25 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"names.select { |name| name.start_with?('S') }.map { |name| name.upcase }" | |
], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 26, | |
"text": [ | |
"[\"STEVE\", \"SARAH\"]" | |
] | |
} | |
], | |
"prompt_number": 26 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [], | |
"language": "ruby", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 27 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment