On Sat, Jun 27, 2009 at 4:52 PM, Fabian Streitel<karottenreibe / googlemail.com> wrote: > Though again, do you have a real example of >> when you nil out a set value? I can't picture why I'd do that > > Just imagine you're building some sort of a binary tree structure. > You'd have inner nodes and leafs and you'd probably want > to represent the leafs with nil. Now when you remove a node > at some point, you'll have to set the #left_child accessor (or > whatever you like to call it) to nil... > > Or take an options hash which has to provide a "default" state > so the system can decide whether or not an option was explicitly > set. You'd probably want to use nil for that (at least I would ;-) I didn't mean 'when would you set an attribute to nil' I meant, when would you ever do this with a DSL call? Neither of the examples you mentioned address that. If you don't need to do this in a DSL, attr_writer / attr_accessor already work fine. >> def name(*args) >> return @name if args.empty? >> ¨Âîáíå áòçó®æéòóô >> end > > Better, but IMHO that's WAY too much overhead for something as basic as a > setter. > After all, you have to construct an array everytime you access the setter... Huh? This is the way Ruby arguments work no matter what. Using *args just gives you raw access to the arguments.