Skip to content

Instantly share code, notes, and snippets.

@reinhardt021
Created October 27, 2015 18:08
Show Gist options
  • Save reinhardt021/e4c5120433f88f0ca16f to your computer and use it in GitHub Desktop.
Save reinhardt021/e4c5120433f88f0ca16f to your computer and use it in GitHub Desktop.

Revisions

  1. Reinhardt created this gist Oct 27, 2015.
    177 changes: 177 additions & 0 deletions IRB practice
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,177 @@
    Last login: Tue Oct 27 08:43:36 on ttys000
    Reinhardts-MacBook-Air:lighthouse rhcgr$ vim longest.rb
    Reinhardts-MacBook-Air:lighthouse rhcgr$ ruby longest.rb
    longest.rb:6:in `count': wrong number of arguments (0 for 1+) (ArgumentError)
    from longest.rb:6:in `block in find_longest'
    from longest.rb:5:in `each'
    from longest.rb:5:in `find_longest'
    from longest.rb:13:in `<main>'
    Reinhardts-MacBook-Air:lighthouse rhcgr$ vim longest.rb
    Reinhardts-MacBook-Air:lighthouse rhcgr$ ruby longest.rb
    Reinhardts-MacBook-Air:lighthouse rhcgr$ ruby longest.rb
    Reinhardts-MacBook-Air:lighthouse rhcgr$ vim longest.rb
    Reinhardts-MacBook-Air:lighthouse rhcgr$ ruby longest.rb
    apples
    bananas
    cherries
    durian
    eggplant
    Reinhardts-MacBook-Air:lighthouse rhcgr$ vim longest.rb
    Reinhardts-MacBook-Air:lighthouse rhcgr$ ruby longest.rb
    cherries
    Reinhardts-MacBook-Air:lighthouse rhcgr$ irb
    irb(main):001:0> exit
    Reinhardts-MacBook-Air:lighthouse rhcgr$ vagrant up
    Bringing machine 'default' up with 'virtualbox' provider...
    ==> default: Clearing any previously set forwarded ports...
    ==> default: Clearing any previously set network interfaces...
    ==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    ==> default: Forwarding ports...
    default: 3000 => 3000 (adapter 1)
    default: 3001 => 3001 (adapter 1)
    default: 22 => 2222 (adapter 1)
    ==> default: Booting VM...
    ==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    ==> default: Machine booted and ready!
    ==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 4.3.20
    default: VirtualBox Version: 5.0
    ==> default: Mounting shared folders...
    default: /vagrant => /Users/rhcgr/lighthouse
    ==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
    ==> default: flag to force provisioning. Provisioners marked to run always will still run.
    Reinhardts-MacBook-Air:lighthouse rhcgr$ vagrant ssh
    Welcome to Ubuntu 12.04.4 LTS (GNU/Linux 3.2.0-65-generic-pae i686)

    * Documentation: https://help.ubuntu.com/
    Welcome to your Vagrant-built virtual machine.
    Last login: Tue Oct 27 00:13:00 2015 from 10.0.2.2
    vagrant [vagrant]> irb
    2.1.3 :001 > puts "hello"
    hello
    => nil
    2.1.3 :002 > "Khurram".reverse
    => "marruhK"
    2.1.3 :003 > quit
    vagrant [vagrant]> gem install pry
    Fetching: method_source-0.8.2.gem (100%)
    Successfully installed method_source-0.8.2
    Fetching: slop-3.6.0.gem (100%)
    Successfully installed slop-3.6.0
    Fetching: coderay-1.1.0.gem (100%)
    Successfully installed coderay-1.1.0
    Fetching: pry-0.10.3.gem (100%)
    Successfully installed pry-0.10.3
    invalid options: -SNw2
    (invalid options are ignored)
    Parsing documentation for coderay-1.1.0
    Installing ri documentation for coderay-1.1.0
    Parsing documentation for method_source-0.8.2
    Installing ri documentation for method_source-0.8.2
    Parsing documentation for pry-0.10.3
    Installing ri documentation for pry-0.10.3
    Parsing documentation for slop-3.6.0
    Installing ri documentation for slop-3.6.0
    Done installing documentation for coderay, method_source, pry, slop after 6 seconds
    4 gems installed
    vagrant [vagrant]> pry
    [1] pry(main)> puts "hello"
    hello
    => nil
    [2] pry(main)> "Khurram".reverse
    => "marruhK"
    [3] pry(main)> quit
    vagrant [vagrant]> mkdir w1d2/
    vagrant [vagrant]> ls
    git-mania longest.rb temp_test_file.txt vi-vim-cheat-sheet.gif
    index.html scavenger_hunt-master Vagrantfile w1d2
    vagrant [vagrant]> cd w1d2
    vagrant [w1d2]> ls
    vagrant [w1d2]> touch example.rb
    vagrant [w1d2]> ls
    example.rb
    vagrant [w1d2]> open
    Couldn't get a file descriptor referring to the console
    vagrant [w1d2]> open .
    Couldn't get a file descriptor referring to the console
    vagrant [w1d2]> ruby example.rb
    Enter your name: example.rb:2:in `<main>': undefined local variable or method `gest' for main:Object (NameError)
    vagrant [w1d2]> ruby example.rb
    Enter your name: Reinhardt
    Hello, Reinhardt
    vagrant [w1d2]> pry
    [1] pry(main)> "Khurram".reverse
    => "marruhK"
    [2] pry(main)> ruby example.rb
    NameError: undefined local variable or method `example' for main:Object
    from (pry):2:in `__pry__'
    [3] pry(main)> quit
    vagrant [w1d2]> pry
    [1] pry(main)> quit
    vagrant [w1d2]> irb
    2.1.3 :001 > def say_hi(name)
    2.1.3 :002?> "Hi, #{name}"
    2.1.3 :003?> end
    => :say_hi
    2.1.3 :004 > say_hi("Josh")
    => "Hi, Josh"
    2.1.3 :005 > my_array = [5,3,7,2]
    => [5, 3, 7, 2]
    2.1.3 :006 > my_array.sort
    => [2, 3, 5, 7]
    2.1.3 :007 > my_array
    => [5, 3, 7, 2]
    2.1.3 :008 > my_array.sort!
    => [2, 3, 5, 7]
    2.1.3 :009 > my_array
    => [2, 3, 5, 7]
    2.1.3 :010 > my_array.shuffle
    => [2, 5, 3, 7]
    2.1.3 :011 > my_array.transpose
    TypeError: no implicit conversion of Fixnum into Array
    from (irb):11:in `transpose'
    from (irb):11
    from /usr/local/rvm/rubies/ruby-2.1.3/bin/irb:11:in `<main>'
    2.1.3 :012 > my_array.slice
    ArgumentError: wrong number of arguments (0 for 1..2)
    from (irb):12:in `slice'
    from (irb):12
    from /usr/local/rvm/rubies/ruby-2.1.3/bin/irb:11:in `<main>'
    2.1.3 :013 > my_array.reverse
    => [7, 5, 3, 2]
    2.1.3 :014 > my_array
    => [2, 3, 5, 7]
    2.1.3 :015 > my_array.reverse!
    => [7, 5, 3, 2]
    2.1.3 :016 > my_array
    => [7, 5, 3, 2]
    2.1.3 :017 > an_array = ['Hello', 'nurse', 'and', 'world']
    => ["Hello", "nurse", "and", "world"]
    2.1.3 :018 > an_array.each { |word| puts word}
    Hello
    nurse
    and
    world
    => ["Hello", "nurse", "and", "world"]
    2.1.3 :019 > Math.sqrt(1282)
    => 35.805027579936315
    2.1.3 :020 > Time.now
    => 2015-10-27 18:01:43 +0000
    2.1.3 :021 > Array.new(10, 'bee')
    => ["bee", "bee", "bee", "bee", "bee", "bee", "bee", "bee", "bee", "bee"]
    2.1.3 :022 > include Math
    => Object
    2.1.3 :023 > sqrt 64
    => 8.0
    2.1.3 :024 >