From: brabuhr@... Date: 2012-01-28T09:02:50+09:00 Subject: Re: Why is a = a nil instead of giving NameError On Fri, Jan 27, 2012 at 6:40 PM, Navindra Umanee wrote: > Could someone help me understand what is happening here? > > irb(main):005:0> a = a > => nil > > a is undefined, so why does "a = a" work instead of giving a NameError > like "b = c" does? https://github.com/michaeledgar/ripper-plus "Local variables are created immediately when the Ruby parser parses a left-hand-side local variable. Before the right-hand-side is even parsed, the local variable has been created. This also results in an infamous anomaly: def say_what? x = 'hello' unless defined?(x) puts x end say_what? prints a blank line! This is because as soon as the x on the LHS is parsed, x is a local variable with value nil. By the time defined?(x) is executed, x has long since been a local variable!"