Monthly Archives: June 2015

Variable assignment quirks in Ruby

# irb
irb(main):001:0> puts x
NameError: undefined local variable or method 'x' for main:Object
	from (irb):1
	from /usr/bin/irb:11:in '<main>'

Okay. I expected that.

irb(main):002:0> x = x + 1
NoMethodError: undefined method '+' for nil:NilClass
	from (irb):2
	from /usr/bin/irb:11:in '<main>'

Whoa. Did NOT expect that! Wait, so does that mean…?

irb(main):003:0> z = z
=> nil

Hmm. Okay. Well, time to call it a day.