R
Ruby Freak
The defined? keyword seems to have some funky behaviors.
I have decided that the best way to use it is to compare the output to
nil as it returns a myriad of results that all result in truth.
puts (defined?(x) == nil ? "Not defined" : "Is defined")
but...
What's up with y?
The uninitialized variable y returns from defined? as "method" rather
than "nil" ????
puts defined?(x) # => nil
puts defined?(y) # => method
At least this happens on my buddy's win XP box that I am using, to
play with Ruby. Maybe the box is spanked as this doesn't seem to
happen in the online ruby demo at http://tryruby.hobix.com/
I am sure there is a stupid simple answer, but it eludes me.
Thanks
I have decided that the best way to use it is to compare the output to
nil as it returns a myriad of results that all result in truth.
puts (defined?(x) == nil ? "Not defined" : "Is defined")
but...
What's up with y?
The uninitialized variable y returns from defined? as "method" rather
than "nil" ????
puts defined?(x) # => nil
puts defined?(y) # => method
At least this happens on my buddy's win XP box that I am using, to
play with Ruby. Maybe the box is spanked as this doesn't seem to
happen in the online ruby demo at http://tryruby.hobix.com/
I am sure there is a stupid simple answer, but it eludes me.
Thanks