From: pat eyler Date: 2011-03-21T13:14:25+09:00 Subject: Re: Logical OR in Ruby On Sun, Mar 20, 2011 at 10:09 PM, Paul Sholtz wrote: > I'm looking at some source code, to try and understand it. > > There's a variable "weight", and then there's this call: > > weight ||= 100 > > which I take to be equivalent to: > > weight = weight || 100 > > (i.e., performing a logical OR between "weight" and 100). > > What I think this code means, is that the value that will be assigned to > "weight" will be either (a) "weight" (if weight has already been > assigned) or else (b) if "weight" is presently nil, then the value 100 > will be assigned to "weight" instead. > > Is this correct? > yes. Generally, you'll find irb to be very helpful in finding things like this out: irb(main):001:0> foo ||= 10 => 10 irb(main):002:0> foo => 10 irb(main):003:0> foo ||=100 => 10 irb(main):004:0> foo => 10 irb(main):005:0> > -- > Posted via http://www.ruby-forum.com/. > > -- thanks, -pate -------------------------  Don't judge those who choose to sin differently than you do