Created
March 3, 2015 22:09
-
-
Save raySavignone/d019ffc19ecc7ed46104 to your computer and use it in GitHub Desktop.
Playing around with irb
This file contains 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
vagrant [day_2]> irb | |
2.1.3 :001 > puts "hello" | |
hello | |
=> nil | |
2.1.3 :002 > "khurram".reverse | |
=> "marruhk" | |
2.1.3 :003 > ramon | |
NameError: undefined local variable or method `ramon' for main:Object | |
from (irb):3 | |
from /usr/local/rvm/rubies/ruby-2.1.3/bin/irb:11:in `<main>' | |
2.1.3 :004 > "ramon".reverse | |
=> "nomar" | |
2.1.3 :005 > quit | |
vagrant [day_2]> ls | |
lecture_2.txt | |
vagrant [day_2]> touch ruby.rb | |
vagrant [day_2]> ls | |
lecture_2.txt ruby.rb | |
vagrant [day_2]> ls | |
lecture_2.txt ruby.rb | |
vagrant [day_2]> ruby ruby.rb | |
Enter your name: ramon | |
hello ramon | |
vagrant [day_2]> irb | |
2.1.3 :001 > def say_hi | |
2.1.3 :002?> end | |
=> :say_hi | |
2.1.3 :003 > def say_hi | |
2.1.3 :004?> end | |
=> :say_hi | |
2.1.3 :005 > def say_hi(name) | |
2.1.3 :006?> puts "Hi #{nam}" | |
2.1.3 :007?> end | |
=> :say_hi | |
2.1.3 :008 > say_hi(ramon) | |
NameError: undefined local variable or method `ramon' for main:Object | |
from (irb):8 | |
from /usr/local/rvm/rubies/ruby-2.1.3/bin/irb:11:in `<main>' | |
2.1.3 :009 > say_hi("ramon") | |
NameError: undefined local variable or method `nam' for main:Object | |
from (irb):6:in `say_hi' | |
from (irb):9 | |
from /usr/local/rvm/rubies/ruby-2.1.3/bin/irb:11:in `<main>' | |
2.1.3 :010 > def say_hi(name) | |
2.1.3 :011?> puts "Hi #{name}" | |
2.1.3 :012?> end | |
=> :say_hi | |
2.1.3 :013 > say_hi("ramon") | |
Hi ramon | |
=> nil | |
2.1.3 :014 > s = "ramon" | |
=> "ramon" | |
2.1.3 :015 > s.inspect | |
=> "\"ramon\"" | |
2.1.3 :016 > s.class | |
=> String | |
2.1.3 :017 > s.length | |
=> 5 | |
2.1.3 :018 > s.average | |
NoMethodError: undefined method `average' for "ramon":String | |
from (irb):18 | |
from /usr/local/rvm/rubies/ruby-2.1.3/bin/irb:11:in `<main>' | |
2.1.3 :019 > s.collect | |
NoMethodError: undefined method `collect' for "ramon":String | |
from (irb):19 | |
from /usr/local/rvm/rubies/ruby-2.1.3/bin/irb:11:in `<main>' | |
2.1.3 :020 > arr = [2,2,22,222] | |
=> [2, 2, 22, 222] | |
2.1.3 :021 > arr.inspect | |
=> "[2, 2, 22, 222]" | |
2.1.3 :022 > arrr.class | |
NameError: undefined local variable or method `arrr' for main:Object | |
from (irb):22 | |
from /usr/local/rvm/rubies/ruby-2.1.3/bin/irb:11:in `<main>' | |
2.1.3 :023 > arr.class | |
=> Array | |
2.1.3 :024 > arr.sort | |
=> [2, 2, 22, 222] | |
2.1.3 :025 > arr | |
=> [2, 2, 22, 222] | |
2.1.3 :026 > arr.reverse | |
=> [222, 22, 2, 2] | |
2.1.3 :027 > arr | |
=> [2, 2, 22, 222] | |
2.1.3 :028 > arr.reverse! | |
=> [222, 22, 2, 2] | |
2.1.3 :029 > arr | |
=> [222, 22, 2, 2] | |
2.1.3 :030 > arr.each do |element| | |
2.1.3 :031 > puts element | |
2.1.3 :032?> end | |
222 | |
22 | |
2 | |
2 | |
=> [222, 22, 2, 2] | |
2.1.3 :033 > Math.sqrt(9) | |
=> 3.0 | |
2.1.3 :034 > Time.now | |
=> 2015-03-03 22:05:10 +0000 | |
2.1.3 :035 > Array.new(10,'bee') | |
=> ["bee", "bee", "bee", "bee", "bee", "bee", "bee", "bee", "bee", "bee"] | |
2.1.3 :036 > include Math | |
=> Object | |
2.1.3 :037 > sqrt 64 | |
=> 8.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment