From: Rick DeNatale Date: 2008-04-06T04:51:42+09:00 Subject: Re: The ||= assignment operator On Sat, Apr 5, 2008 at 12:08 PM, David A. Black wrote: > The only time this matters is with hashes that have default values. In > every other case, as far as I know, x = x || y also describes what's > happening. Well here's another: class Foo attr_writer :x def x @x || 1 # !> instance variable @x not initialized end def inspect "Foo(#{@x})" # !> instance variable @x not initialized end end f = Foo.new f.x # => 1 f # => Foo() f.x ||= 2 f.x # => 1 f # => Foo() f.x || f.x = 2 f.x # => 1 f # => Foo() f.x = f.x || 2 f.x # => 1 f # => Foo(1) -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/