From: Tim Greer Date: 2009-01-10T08:29:38+09:00 Subject: Re: value of an expression? Kedar Mhaswade wrote: > >> It is the equivalent of: >> >> if (1 + 1 != 2) >> s = "surprising" >> end >> >> So s = "surprising" is never evaluated, and s continues to equal >> "test". > > Ah ok, thanks. However, I was thinking if it should be nil, not > "surprising", because of the following experience with irb: > >>> "surprising" if (1+1 !=2) > => nil > > which gives an impression that the value of this entire expression is > nil. > > -Kedar > That's because the conditional isn't true. If the conditional wasn't nil, it would have a result (no result is nil): irb(main):008:0> s = "surprising" if (1+1 != 2) => nil irb(main):009:0> s = "surprising" if (1+1 == 2) => "surprising" irb(main):010:0> See, for example: irb(main):010:0> s = 'value' => "value" See that "puts s" has no result, you see => nil. irb(main):011:0> puts s value => nil It does what it is supposed to do: irb(main):010:0> s = 'value' => "value" irb(main):011:0> puts s value => nil irb(main):013:0> s = "surprising" if (1+1 != 2) => nil <- conditional false, nil. irb(main):014:0> puts s value => nil irb(main):015:0> s = "surprising" if (1+1 == 2) => "surprising" <- conditional true, not nil. irb(main):016:0> puts s surprising => nil These results don't change what 's' is assigned, unless it's true and s is assigned a different value. I hope that makes sense. -- Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc. Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers and Custom Hosting. 24/7 support, 30 day guarantee, secure servers. Industry's most experienced staff! -- Web Hosting With Muscle!