I thought in the following, foo should be true
$ irb
ruby-1.9.2-p0 > foo = true if !defined? foo || foo.nil?
=> nil
ruby-1.9.2-p0 > foo
=> nil
because foo was at first not defined, but the foo = true part make it temporarily has a nil value, so the !defined didn’t catch it, but the foo.nil? should catch it, and make it true… but why is it still nil?
this is related to Ruby's "foo = true if !defined? foo" won't work as expected
Be careful when skipping parenthesis. You meant:
As per your other question, the
defined?(foo)will always betrue, so really you want to write: