Skip to content

Instantly share code, notes, and snippets.

@olp-cs
Last active October 5, 2015 13:48
Show Gist options
  • Save olp-cs/2815422 to your computer and use it in GitHub Desktop.
Save olp-cs/2815422 to your computer and use it in GitHub Desktop.
How Ruby interpreter works
irb(main):014:0> if 1==2
irb(main):015:1> print "True"
irb(main):016:1> ense
irb(main):017:1> print "False"
irb(main):018:1> end
=> nil
# Why nil?
# No answer? Hint: Let's look at different cases
irb(main):001:0> ense
NameError: undefined local variable or method `ense' for main:Object
from (irb):1
from /usr/local/bin/irb:12:in `<main>'
irb(main):002:0> if 1==1
irb(main):003:1> ense
irb(main):004:1> end
NameError: undefined local variable or method `ense' for main:Object
from (irb):3
from /usr/local/bin/irb:12:in `<main>'
irb(main):005:0> if 1==1
irb(main):006:1> print "True"
irb(main):007:1> ense
irb(main):008:1> end
TrueNameError: undefined local variable or method `ense' for main:Object
from (irb):7
from /usr/local/bin/irb:12:in `<main>'
irb(main):009:0> if 1==1
irb(main):010:1> print "True"
irb(main):011:1> ense
irb(main):012:1> print "False"
irb(main):013:1> end
TrueNameError: undefined local variable or method `ense' for main:Object
from (irb):11
from /usr/local/bin/irb:12:in `<main>'
irb(main):014:0> if 1==2
irb(main):015:1> print "True"
irb(main):016:1> ense
irb(main):017:1> print "False"
irb(main):018:1> end
=> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment