Hello,
I was writing a small Heap implementation and upon creating my Node class I noticed some weird behaviour. I wanted to call defined?(x)
to ensure x
was defined, then check if x
was an Integer, before storing it in the Node's value class variable. In IRB I can call
defined?(x)
and the result is nil.
However, in the class, I try this:
def change_value value
@value = value if defined?(value)
end
and the result when I call the change_value
with a random letter, let's say 'e', is the standard undefined local variable or method error. Again, in IRB it seems to work fine and I am wondering if I have some kind of environment issue or if this is not the 'best' way to check if value is really there.
Thanks.