From: Glen Holcomb Date: 2008-04-05T04:25:04+09:00 Subject: Re: The ||= assignment operator ------=_Part_10860_905779.1207337102166 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Fri, Apr 4, 2008 at 1:11 PM, Belorion wrote: > It was my understanding that the ||= assignment operator assigned the > value > on the right-hand side if and only if the left hand side did not already > have a value: > > irb(main):001:0> x = true > => true > irb(main):002:0> x ||= "ruby" > => true > irb(main):003:0> x > => true > And, likewise, with nil: > > irb(main):014:0> x = nil > => nil > irb(main):015:0> x ||= "ruby" > => "ruby" > irb(main):016:0> x > => "ruby" > However, I do not understand this behavior: > > irb(main):019:0> x = false > => false > irb(main):020:0> x ||= "ruby" > => "ruby" > irb(main):021:0> x > => "ruby" > > > We know that false != nil, and yet the ||= will assign if the left hand > side > is false? > > regards, > Matt > Nope ||= will assign if nil or false. -- "Hey brother Christian with your high and mighty errand, Your actions speak so loud, I can't hear a word you're saying." -Greg Graffin (Bad Religion) ------=_Part_10860_905779.1207337102166--