From: Robert Klemme Date: 2008-04-11T18:58:09+09:00 Subject: Re: var = nil if false; p var.nil? #=> true | bug of the day ? 2008/4/11, Phillip Gawlowski : > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Arie Kusuma Atmaja wrote: > | I tested it using Ruby 1.8.6 patch 111 and also Ruby 1.9.0 (revision > 15968). > | > | var = nil if false > | var.nil? #=> true > | > | I actually saw it from tobi's blog, then I discussed with a perler who > | loves ruby as well, here's a copy paste. (Bottomline: is it a feature > | or a bug????) > > irb(main):001:0> something = "something" if false > => nil > irb(main):002:0> something_else = nil > => nil > irb(main):003:0> something_else.class > => NilClass > irb(main):004:0> exit Be careful when testing issues that involve local variables in IRB. Top level local variables such as these do behave differently in IRB. Cheers robert -- use.inject do |as, often| as.you_can - without end