Belorion
4/4/2008 7:42:00 PM
[Note: parts of this message were removed to make it a legal post.]
Thanks all, that clears up my understanding. I hadn't thought of it as x =
x || "ruby" (even thoughI knew that x += 1 is the same as x = x + 1) and
that in that expanded case, x evaluates, logistically, to false if nil or
false.
Matt
On Fri, Apr 4, 2008 at 2:28 PM, Todd Benson <caduceass@gmail.com> wrote:
> On Fri, Apr 4, 2008 at 2:11 PM, Belorion <belorion@gmail.com> 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
>
> The operators are working with a three-valued logic. In a comparison,
> a FalseClass object or a NilClass object will be logistically false.
>
> Todd
>
>