Skip to content

Instantly share code, notes, and snippets.

@ambsvan
Created June 3, 2014 19:30
Show Gist options
  • Save ambsvan/6e287c0d3ed175bbd7df to your computer and use it in GitHub Desktop.
Save ambsvan/6e287c0d3ed175bbd7df to your computer and use it in GitHub Desktop.
Interactive Ruby (Practice)
* Documentation: https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Mon Jun 2 20:21:23 2014 from 10.0.2.2
vagrant [~]> touch hello.rb
vagrant [~]> cd vagrant
-bash: cd: vagrant: No such file or directory
vagrant [~]> ls
git-mania hello.rb index.html ls.txt post.html postinstall.sh tmp work
vagrant [~]> ls
git-mania hello.rb index.html ls.txt post.html postinstall.sh tmp work
vagrant [~]> cd va
-bash: cd: va: No such file or directory
vagrant [~]> cd /
vagrant [/]> cd vagrant/
vagrant [vagrant]> touch hello.rb
vagrant [vagrant]> ruby hello.rb
hello
vagrant [vagrant]> ruby hello.rb
hello
hello.rb:6:in `<main>': undefined local variable or method `message' for main:Object (NameError)
vagrant [vagrant]> ruby hello.rb
hello
vagrant [vagrant]> ruby hello.rb
hello
hello
vagrant [vagrant]> ruby hello.rb
hello
guy
vagrant [vagrant]> ruby hello.rb
hello
hello
vagrant [vagrant]> ruby hello.rb
hello
hello
false
vagrant [vagrant]> ruby hello.rb
hello
hello
true
vagrant [vagrant]> ruby hello.rb
hello
hello
true
true
vagrant [vagrant]> ruby hello.rb
hello
hello
true
9
vagrant [vagrant]> quit
No command 'quit' found, did you mean:
Command 'quilt' from package 'quilt' (main)
Command 'luit' from package 'x11-utils' (main)
Command 'quot' from package 'quota' (main)
Command 'quiz' from package 'bsdgames' (universe)
Command 'qgit' from package 'qgit' (universe)
quit: command not found
vagrant [vagrant]> cd vagrant
-bash: cd: vagrant: No such file or directory
vagrant [vagrant]> ls
git-mania lighthouse-vagrant.box temp_test_file.txt Vagrantfile
hello.rb Notes Week 1 Day 2 vagrant_1.6.3.msi Work
vagrant [vagrant]> git init
Initialized empty Git repository in /vagrant/.git/
vagrant [vagrant (master)⚡]> git add work
vagrant [vagrant (master)⚡]> ls -la
total 1375740
drwxr-xr-x 1 vagrant vagrant 442 Jun 3 2014 .
drwxr-xr-x 23 root root 4096 Oct 23 2013 ..
-rw-r--r-- 1 vagrant vagrant 6148 Jun 3 17:55 .DS_Store
drwxr-xr-x 1 vagrant vagrant 340 Jun 3 2014 .git
drwxr-xr-x 1 vagrant vagrant 136 Jun 2 22:34 git-mania
-rw-r--r-- 1 vagrant vagrant 769 Jun 3 17:44 hello.rb
-rwxrwxrwx 1 vagrant vagrant 1247199693 Jun 2 14:19 lighthouse-vagrant.box
-rw-r--r-- 1 vagrant vagrant 861 Jun 3 17:40 Notes Week 1 Day 2
-rw-r--r-- 1 vagrant vagrant 0 Jun 2 19:02 temp_test_file.txt
drwxr-xr-x 1 vagrant vagrant 102 Jun 2 18:54 .vagrant
-rwxrwxrwx 1 vagrant vagrant 161525760 Jun 2 14:05 vagrant_1.6.3.msi
-rw-r--r-- 1 vagrant vagrant 4825 Jun 2 18:54 Vagrantfile
drwxr-xr-x 1 vagrant vagrant 170 Jun 3 17:33 Work
vagrant [vagrant (master)⚡]> cd ..
vagrant [/]> ls -la
total 85
drwxr-xr-x 23 root root 4096 Oct 23 2013 .
drwxr-xr-x 23 root root 4096 Oct 23 2013 ..
drwxr-xr-x 2 root root 4096 Sep 14 2012 bin
drwxr-xr-x 4 root root 1024 Sep 14 2012 boot
drwxr-xr-x 14 root root 4160 Jun 2 18:58 dev
drwxr-xr-x 90 root root 4096 Jun 2 18:58 etc
drwxr-xr-x 3 root root 4096 Sep 14 2012 home
lrwxrwxrwx 1 root root 37 Sep 14 2012 initrd.img -> /boot/initrd.img-3.2.0-23-generic-pae
drwxr-xr-x 19 root root 4096 Sep 14 2012 lib
drwx------ 2 root root 16384 Sep 14 2012 lost+found
drwxr-xr-x 4 root root 4096 Sep 14 2012 media
drwxr-xr-x 2 root root 4096 Apr 19 2012 mnt
-r-------- 1 root root 80 Oct 23 2013 .my.cnf
drwxr-xr-x 4 root root 4096 Sep 14 2012 opt
dr-xr-xr-x 88 root root 0 Jun 2 18:58 proc
drwx------ 3 root root 4096 Oct 23 2013 root
drwxr-xr-x 19 root root 740 Jun 3 16:02 run
drwxr-xr-x 2 root root 4096 Sep 14 2012 sbin
drwxr-xr-x 2 root root 4096 Mar 5 2012 selinux
drwxr-xr-x 2 root root 4096 Sep 14 2012 srv
drwxr-xr-x 13 root root 0 Jun 2 18:58 sys
drwxrwxrwt 6 root root 4096 Jun 3 17:17 tmp
drwxr-xr-x 10 root root 4096 Sep 14 2012 usr
drwxr-xr-x 1 vagrant vagrant 442 Jun 3 2014 vagrant
drwxr-xr-x 11 root root 4096 Jun 2 14:15 var
lrwxrwxrwx 1 root root 33 Sep 14 2012 vmlinuz -> boot/vmlinuz-3.2.0-23-generic-pae
vagrant [/]> cd vagrant
vagrant [vagrant (master)⚡]> ls
git-mania lighthouse-vagrant.box temp_test_file.txt Vagrantfile
hello.rb Notes Week 1 Day 2 vagrant_1.6.3.msi Work
vagrant [vagrant (master)⚡]> rm -rf
vagrant [vagrant (master)⚡]> rm -rf .git
vagrant [vagrant]> mk dir work
mk: command not found
vagrant [vagrant]> mkdir
mkdir: missing operand
Try `mkdir --help' for more information.
vagrant [vagrant]> ls
git-mania lighthouse-vagrant.box temp_test_file.txt Vagrantfile
hello.rb Notes Week 1 Day 2 vagrant_1.6.3.msi Work
vagrant [vagrant]> mkdir work
mkdir: cannot create directory `work': File exists
vagrant [vagrant]> touch Work
vagrant [vagrant]> ls
git-mania lighthouse-vagrant.box temp_test_file.txt Vagrantfile
hello.rb Notes Week 1 Day 2 vagrant_1.6.3.msi Work
vagrant [vagrant]> cd work
vagrant [work]> ls
Day 1 Week 1.mdown Week 1
vagrant [work]> ..cd
..cd: command not found
vagrant [work]> cd..
cd..: command not found
vagrant [work]> .. cd
..: command not found
vagrant [work]> cd ..
vagrant [vagrant]> mkdir week1
vagrant [vagrant]> cd week1
vagrant [week1]> git init
Initialized empty Git repository in /vagrant/week1/.git/
vagrant [week1 (master)⚡]> git add work
fatal: pathspec 'work' did not match any files
vagrant [week1 (master)⚡]> ls
vagrant [week1 (master)⚡]> ls
Day 1 Week 1.mdown hello.rb Notes Week 1 Day 2
vagrant [week1 (master)⚡]> git add hello.rb
vagrant [week1 (master)⚡]> git commit -m "add morning exercise"
[master (root-commit) d7684da] add morning exercise
1 file changed, 12 insertions(+)
create mode 100644 hello.rb
HWork.gitweek1 (master)⚡]> git remote add origin https://github.com/ambsvan/L
vagrant [week1 (master)⚡]> git remote -v
origin https://github.com/ambsvan/LHWork.git (fetch)
origin https://github.com/ambsvan/LHWork.git (push)
vagrant [week1 (master)⚡]> git push -u origin master
Username for 'https://github.com': ambsvan
Password for 'https://[email protected]':
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 481 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/ambsvan/LHWork.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
vagrant [week1 (master)⚡]> ls
Day 1 Week 1.mdown hello.rb Notes Week 1 Day 2
vagrant [week1 (master)⚡]> rm -rf .git
vagrant [week1]> ~cd
No command '~cd' found, did you mean:
Command 'hcd' from package 'hfsutils' (main)
Command 'mcd' from package 'mtools' (main)
Command 'ncd' from package 'complearn-tools' (universe)
Command 'bcd' from package 'bsdgames' (universe)
~cd: command not found
vagrant [week1]> cd~
No command 'cd~' found, did you mean:
Command 'cdb' from package 'tinycdb' (main)
Command 'cdo' from package 'cdo' (universe)
Command 'cdi' from package 'cdo' (universe)
Command 'cdv' from package 'codeville' (universe)
Command 'cdw' from package 'cdw' (universe)
Command 'cdp' from package 'irpas' (multiverse)
Command 'cd5' from package 'cd5' (universe)
cd~: command not found
vagrant [week1]> cd ~
vagrant [~]> ls
git-mania hello.rb index.html ls.txt post.html postinstall.sh tmp work
vagrant [~]> irb
2.0.0-p247 :001 > gem install pry
NameError: undefined local variable or method `pry' for main:Object
from (irb):1
from /usr/local/rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'
2.0.0-p247 :002 > gem install pry
NameError: undefined local variable or method `pry' for main:Object
from (irb):2
from /usr/local/rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'
2.0.0-p247 :003 > quit
vagrant [~]> gem install pry
Successfully installed pry-0.9.12.6
Installing ri documentation for pry-0.9.12.6
1 gem installed
vagrant [~]> ls
git-mania hello.rb index.html ls.txt post.html postinstall.sh tmp work
vagrant [~]> mkdir example.rb
vagrant [~]> ls
example.rb hello.rb ls.txt postinstall.sh work
git-mania index.html post.html tmp
vagrant [~]> ls
example.rb hello.rb ls.txt postinstall.sh work
git-mania index.html post.html tmp
vagrant [~]> cd example.rb
vagrant [example.rb]> ls
vagrant [example.rb]> .. cs
..: command not found
vagrant [example.rb]> .. cd
..: command not found
vagrant [example.rb]> cd ..
vagrant [~]> ls
example.rb hello.rb ls.txt postinstall.sh work
git-mania index.html post.html tmp
vagrant [~]> ls
example.rb hello.rb ls.txt postinstall.sh work
git-mania index.html post.html tmp
vagrant [~]> cd example.rb
vagrant [example.rb]> pry example.rb
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/pry-0.9.12.6/lib/pry/repl_file_loader.rb:16:in `initialize': No such file: /home/vagrant/example.rb/example.rb (RuntimeError)
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/pry-0.9.12.6/lib/pry/pry_class.rb:179:in `new'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/pry-0.9.12.6/lib/pry/pry_class.rb:179:in `load_file_through_repl'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/pry-0.9.12.6/lib/pry/cli.rb:192:in `block in <top (required)>'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/pry-0.9.12.6/lib/pry/cli.rb:70:in `call'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/pry-0.9.12.6/lib/pry/cli.rb:70:in `block in parse_options'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/pry-0.9.12.6/lib/pry/cli.rb:70:in `each'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/pry-0.9.12.6/lib/pry/cli.rb:70:in `parse_options'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/pry-0.9.12.6/bin/pry:16:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.0.0-p247/bin/pry:23:in `load'
from /usr/local/rvm/gems/ruby-2.0.0-p247/bin/pry:23:in `<main>'
from /usr/local/rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `eval'
from /usr/local/rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `<main>'
vagrant [example.rb]> pry
[1] pry(main)> example.rb
NameError: undefined local variable or method `example' for main:Object
from (pry):1:in `__pry__'
[2] pry(main)> pry example.rb
NameError: undefined local variable or method `example' for main:Object
from (pry):2:in `__pry__'
[3] pry(main)> ruby example.rb
NameError: undefined local variable or method `example' for main:Object
from (pry):3:in `__pry__'
[4] pry(main)>
[5] pry(main)> quit
vagrant [example.rb]> quit
No command 'quit' found, did you mean:
Command 'quilt' from package 'quilt' (main)
Command 'luit' from package 'x11-utils' (main)
Command 'quot' from package 'quota' (main)
Command 'quiz' from package 'bsdgames' (universe)
Command 'qgit' from package 'qgit' (universe)
quit: command not found
vagrant [example.rb]> exit
logout
Connection to 127.0.0.1 closed.
Ambers-MacBook-Air:Lighthouse amberspencer$ vagrant ssh
/Users/amberspencer/.vagrant.d/boxes/lighthouse-vagrant/0/virtualbox/include/_Vagrantfile:5: warning: already initialized constant VAGRANTFILE_API_VERSION
/Users/amberspencer/Documents/Lighthouse/Vagrantfile:5: warning: previous definition of VAGRANTFILE_API_VERSION was here
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)
* Documentation: https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Tue Jun 3 16:02:24 2014 from 10.0.2.2
vagrant [~]> ls
example.rb hello.rb ls.txt postinstall.sh work
git-mania index.html post.html tmp
vagrant [~]> pry
[1] pry(main)> irb example.rb
NameError: undefined local variable or method `example' for main:Object
from (pry):1:in `__pry__'
[2] pry(main)> ls
self.methods: inspect to_s
locals: _ __ _dir_ _ex_ _file_ _in_ _out_ _pry_
[3] pry(main)> exit
vagrant [~]> ls
example.rb hello.rb ls.txt postinstall.sh work
git-mania index.html post.html tmp
vagrant [~]> cd wor
-bash: cd: wor: No such file or directory
vagrant [~]> cd work
vagrant [work]> ls
vagrant [work]> ls
vagrant [work]> ls
vagrant [work]> cd ..
vagrant [~]> ls
example.rb hello.rb ls.txt postinstall.sh work
git-mania index.html post.html tmp
vagrant [~]> cd /vagrant
vagrant [vagrant]> ls
Day_1 git-mania Notes Week 1 Day 2 Vagrantfile
Day_2 hello.rb temp_test_file.txt
example.rb lighthouse-vagrant.box vagrant_1.6.3.msi
vagrant [vagrant]> vi ~/.profile
vagrant [vagrant]> cd day_2
vagrant [day_2]> pry example.rb
Enter your name: Hello, print "Enter your name: "
vagrant [day_2]> pry example.rb
Enter your name: Hello, print "Enter your name: "
vagrant [day_2]> pry example.rb
Enter your name: Hello, print "Enter your name: "
vagrant [day_2]> pry example.rb
Enter your name: Hello, print "Enter your name: "
vagrant [day_2]> ruby example.rb
Enter your name: Amber
Hello, Amber
vagrant [day_2]> irb
2.0.0-p247 :001 > ruby example.rb
NameError: undefined local variable or method `example' for main:Object
from (irb):1
from /usr/local/rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'
2.0.0-p247 :002 > ruby example.rb
NameError: undefined local variable or method `example' for main:Object
from (irb):2
from /usr/local/rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'
2.0.0-p247 :003 > ruby example.rb
NameError: undefined local variable or method `example' for main:Object
from (irb):3
from /usr/local/rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'
2.0.0-p247 :004 > ruby example.rb
NameError: undefined local variable or method `example' for main:Object
from (irb):4
from /usr/local/rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'
2.0.0-p247 :005 > ruby example.rb
NameError: undefined local variable or method `example' for main:Object
from (irb):5
from /usr/local/rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'
2.0.0-p247 :006 > ruby example.rb
NameError: undefined local variable or method `example' for main:Object
from (irb):6
from /usr/local/rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'
2.0.0-p247 :007 > ruby example.rb
NameError: undefined local variable or method `example' for main:Object
from (irb):7
from /usr/local/rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'
2.0.0-p247 :008 > pry
NameError: undefined local variable or method `pry' for main:Object
from (irb):8
from /usr/local/rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'
2.0.0-p247 :009 > exit
vagrant [day_2]> pry
[1] pry(main)> def says_hi (name)
[1] pry(main)* "Hello #{name}"
[1] pry(main)* end
=> nil
[2] pry(main)> says_hi (Amber)
NameError: uninitialized constant Amber
from (pry):4:in `__pry__'
[3] pry(main)> says_hi ("Amber")
=> "Hello Amber"
[4] pry(main)> grades = Hash.new
=> {}
[5] pry(main)> grades ["Amber"] = 100
SyntaxError: unexpected '=', expecting end-of-input
grades ["Amber"] = 100
^
[5] pry(main)> grades["Jim"]=94
=> 94
[6] pry(main)> ["Amber"]=100
SyntaxError: unexpected '=', expecting end-of-input
["Amber"]=100
^
[6] pry(main)> puts grades Jim
NameError: uninitialized constant Jim
from (pry):8:in `__pry__'
[7] pry(main)> "Amber" => 82
SyntaxError: unexpected =>, expecting end-of-input
"Amber" => 82
^
[7] pry(main)> end
SyntaxError: unexpected keyword_end, expecting end-of-input
[7] pry(main)> variable = "string"
=> "string"
[8] pry(main)> string.upcase
NameError: undefined local variable or method `string' for main:Object
from (pry):10:in `__pry__'
[9] pry(main)> irb
NameError: undefined local variable or method `irb' for main:Object
from (pry):11:in `__pry__'
[10] pry(main)> variable = "amber"
=> "amber"
[11] pry(main)> puts variable
amber
=> nil
[12] pry(main)> [ 1, 2, 3].inspect
=> "[1, 2, 3]"
[13] pry(main)> class Baz
[13] pry(main)* def to_s
[13] pry(main)* "baz"
[13] pry(main)* end
[13] pry(main)* end
=> nil
[14] pry(main)> inspect.baz
NoMethodError: undefined method `baz' for "main":String
from (pry):20:in `__pry__'
[15] pry(main)> baz.inspect
NameError: undefined local variable or method `baz' for main:Object
from (pry):21:in `__pry__'
[16] pry(main)> baz.new.inspect
NameError: undefined local variable or method `baz' for main:Object
from (pry):22:in `__pry__'
[17] pry(main)> new_Array = [1, 2, 3, 4, 5]
=> [1, 2, 3, 4, 5]
[18] pry(main)> [1, 2 ,3, 4].each { |x| puts x }
1
2
3
4
=> [1, 2, 3, 4]
[19] pry(main)> new.Array.inspect
NameError: undefined local variable or method `new' for main:Object
from (pry):25:in `__pry__'
[20] pry(main)> new_Array.inspect
=> "[1, 2, 3, 4, 5]"
[21] pry(main)> Math.sqrt(1282)
=> 35.805027579936315
[22] pry(main)> Time.no
NoMethodError: undefined method `no' for Time:Class
from (pry):28:in `__pry__'
[23] pry(main)> Time.now
=> 2014-06-03 19:24:12 +0000
[24] pry(main)> Array.new(10, 'bee')
=> ["bee", "bee", "bee", "bee", "bee", "bee", "bee", "bee", "bee", "bee"]
[25] pry(main)> new_Array.reverse!
=> [5, 4, 3, 2, 1]
[26] pry(main)> puts my_Array
NameError: undefined local variable or method `my_Array' for main:Object
from (pry):32:in `__pry__'
[27] pry(main)> puts new_Array
5
4
3
2
1
=> nil
[28] pry(main)> include Math
=> Object
[29] pry(main)> sqrt 64
=> 8.0
[30] pry(main)>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment