From: Martin DeMello Date: 2005-02-15T02:14:54+09:00 Subject: Re: attr Robert Klemme wrote: > "Martin DeMello" schrieb im Newsbeitrag > > > > It'd be nice to have an operator like || that only failed for nil - that > > way 'false' valued variables wouldn't be splatted by the a ||= b idiom. > > Isn't #nil? sufficient? > > foo = nil > > 5.times do > foo.nil? and begin > foo = false > puts "changed" > end > end That's a lot more verbose, though. And personally, I've only ever used ||= for setting uninitialized values, so it'd definitely have been more useful to have it distinguish between nil and everythingelse. I suppose this would work: class Object def splat(other) self.nil? ? other : self end end foo = foo.splat 5 but I still like the = form. martin