From: Christophe Grandsire Date: 2005-11-23T21:41:34+09:00 Subject: Re: what is the ruby way to do this? Selon "ako..." : > > @attributes = {} > > > > # Assumes the given object quacks on 'key' > > def @attributes.<<( keyed_obj ) > > (self[keyed_obj.key]||=[])< > end > > > > @attributes << a1 > > @attributes << a2 > > @attributes << a3 > > this is something i have never seen. would you explain the 'def' line > above? is this the same as class << @attributes; def << ...; end ? > If I understand correctly you are asking whether: def @attributes.<<(obj) ... end is the same as: class << @attributes def <<(obj) ... end end (I rewrote them because the clash of << as syntax and << as method made it a bit difficult to read). The short answer is "yes". The long asnwer is that both are ways to add a singleton method to a particular object, @attributes in this case. The first one is just shorter and practical when you want to create just one singleton method. But it's mostly a matter of style. -- Christophe Grandsire. http://rainbow.conlang.free.fr It takes a straight mind to create a twisted conlang.