From: Brian Candler Date: 2009-06-29T19:11:43+09:00 Subject: Re: Attr Methods and object setters David Masover wrote: > On Saturday 27 June 2009 10:26:51 pm Daniel DeLorme wrote: > >> Nothing = Object.new >> def name(value = Nothing) >> @name = value unless value == Nothing >> @name >> end > > Ok, I guess you have to be trying, but I can still break this: > > class Everything > def == other > true > end > end > > name Everything.new > > And the way to fix it: > > Nothing = Object.new > def name(value = Nothing) > @name = value unless Nothing == value > @name > end I believe that "same object" is slightly better expressed by: Nothing.equal? value although in this case, for an instance of Object, it should be the same. -- Posted via http://www.ruby-forum.com/.