Skip to content

Instantly share code, notes, and snippets.

@stupeters187
Created March 29, 2016 15:29
Show Gist options
  • Save stupeters187/f925cfd2677df36c44d1 to your computer and use it in GitHub Desktop.
Save stupeters187/f925cfd2677df36c44d1 to your computer and use it in GitHub Desktop.
2.2.1 :001 > def say_hi(name)
2.2.1 :002?> "Hi, #{name}"
2.2.1 :003?> end
=> :say_hi
2.2.1 :004 > say_hi("stu")
=> "Hi, stu"
2.2.1 :005 > my_array = [4, 7, 1, 0]
=> [4, 7, 1, 0]
2.2.1 :006 > my_array.sort
=> [0, 1, 4, 7]
2.2.1 :007 > my_array
=> [4, 7, 1, 0]
2.2.1 :008 > my_array.sort!
=> [0, 1, 4, 7]
2.2.1 :009 > my_array
=> [0, 1, 4, 7]
2.2.1 :010 > an_array = ["stu", "kate", "haggy"]
=> ["stu", "kate", "haggy"]
2.2.1 :011 > an_array.each { |x| puts x }
stu
kate
haggy
=> ["stu", "kate", "haggy"]
2.2.1 :012 > Math.sqrt(1282)
=> 35.805027579936315
2.2.1 :013 > Time.now
=> 2016-03-29 11:26:53 -0400
2.2.1 :014 > array.new (10, 'bee')
SyntaxError: (irb):14: syntax error, unexpected ',', expecting ')'
array.new (10, 'bee')
^
(irb):14: syntax error, unexpected ')', expecting end-of-input
from /Users/stupeters/.rvm/rubies/ruby-2.2.1/bin/irb:11:in `<main>'
2.2.1 :015 > array.new(10, 'bee')
NameError: undefined local variable or method `array' for main:Object
from (irb):15
from /Users/stupeters/.rvm/rubies/ruby-2.2.1/bin/irb:11:in `<main>'
2.2.1 :016 > Array.new(10, 'bee')
=> ["bee", "bee", "bee", "bee", "bee", "bee", "bee", "bee", "bee", "bee"]
2.2.1 :017 > include Math
=> Object
2.2.1 :018 > sqrt 64
=> 8.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment