Thursday, 19 September 2013

Ruby 1.9.3 nil? undefined local variable or method. Is nil? broken?

Ruby 1.9.3 nil? undefined local variable or method. Is nil? broken?

I've been using var.nil? for a while, it's all over my code. Suddenly, I'm
getting undefined local variable or method for the variable with .nil?
after it.
What's going on? is .nil? broken? I even tried it on an IRB online to make
sure it wasn't something in my environment. I should be able to type:
me.nil?
and that should come back as true if the variable hasn't been defined,
that's the whole point, but I get undefined local variable or method me
for main:Object
Maybe I got nil? wrong and have to use something like:
defined?(me) == nil
and .nil? can only be used with an existing object? This was not the way I
understood it. The ruby docs even say this:
nil.nil? -> true
<anything_else>.nil? -> false
Going crazy here.

No comments:

Post a Comment