Ruby's "foo = true if !defined? foo || foo.nil?" won't work -
i thought in following, foo should true
$ irb ruby-1.9.2-p0 > foo = true if !defined? foo || foo.nil? => nil ruby-1.9.2-p0 > foo => nil
because foo @ first not defined, foo = true
part make temporarily has nil value, !defined
didn't catch it, foo.nil?
should catch it, , make true... why still nil?
this related ruby's "foo = true if !defined? foo" won't work expected
be careful when skipping parenthesis. meant:
foo = true if !defined?(foo) || foo.nil?
as per other question, defined?(foo)
true
, want write:
foo = true if foo.nil?
Comments
Post a Comment