Created
June 21, 2016 16:03
-
-
Save Leejojo/754853d890d5efdd871eb8b603f02ced to your computer and use it in GitHub Desktop.
Interactive Ruby (Practice)
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 [vagrant]> irb | |
2.3.0 :001 > def say_hi(name) | |
2.3.0 :002?> "Hi, #{name}" | |
2.3.0 :003?> end | |
=> :say_hi | |
2.3.0 :004 > say_hi("Joanna") | |
=> "Hi, Joanna" | |
2.3.0 :005 > an_array = ['Hello', 'nurse', 'and', 'world'] | |
=> ["Hello", "nurse", "and", "world"] | |
2.3.0 :006 > an_array.each {|word| puts word} | |
Hello | |
nurse | |
and | |
world | |
=> ["Hello", "nurse", "and", "world"] | |
2.3.0 :007 > Math.sqrt(1282) | |
=> 35.805027579936315 | |
2.3.0 :008 > Time.now | |
=> 2016-06-21 15:58:21 +0000 | |
2.3.0 :009 > Array.new(10, 'bee') | |
=> ["bee", "bee", "bee", "bee", "bee", "bee", "bee", "bee", "bee", "bee"] | |
2.3.0 :010 > gem list | |
NameError: undefined local variable or method `list' for main:Object | |
from (irb):10 | |
from /usr/local/rvm/rubies/ruby-2.3.0/bin/irb:11:in `<main>' | |
2.3.0 :011 > quit | |
vagrant [vagrant]> gem install pry | |
Successfully installed pry-0.10.3 | |
1 gem installed | |
vagrant [vagrant]> pry | |
[1] pry(main)> include Math | |
=> Object | |
[2] pry(main)> sqrt 64 | |
=> 8.0 | |
[3] pry(main)> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment