Excerpts from Love U Ruby's message of 2013-11-23 19:44:45 +0100:
> Hi,
> 
> I am having some confusions about local variable assignments..
> 
> x + 1 # undefined local variable or method `x' for main:Object
> (NameError)
> 
> But why not the same error happened in the below case ?
> 
> x = x+1
> # undefined method `+' for nil:NilClass (NoMethodError)
>

Because in the first case, ruby can't know whether x is a method called
without parentheses or a local variable. It opts for the first possibility,
but can't find such a method and raises an exception.

In the second case, instead, ruby sees 
x = 
and understand that x can't be a method (you can't assign to a method),
so it correctly decides x is a local variable. It then attempts to add 1
to x, which is done by calling the + method on x. Of course, x is nil,
so you get a NoMethorError exception.

I hope this helps

Stefano