From: Rick DeNatale Date: 2010-06-18T03:09:27+09:00 Subject: Re: shorthand On Thu, Jun 17, 2010 at 11:07 AM, Brian Candler wrote: > I never said that foo.x ||= 5 behaves like this. This *is* a method call > (:x=) not a local variable assignment. No, but you said that "foo ||= 5 is shorthand for foo = foo || 5" which implies the same semantics, but... class Foo def initialize(x=nil) self.x = x end def x @x end def x=(x) puts "set to #{x}" @x = x end end f = Foo.new f.x ||= 3 f.x ||= 5 f.x = f.x || 6 produces: set to set to 3 set to 3 See the difference? -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale