From: Robert Klemme Date: 2012-05-17T22:03:29+09:00 Subject: Re: Passing attributes to initialize On Wed, May 16, 2012 at 5:32 PM, Matt Mencel wrote: > Thanks Robert, > > Can you explain what these new code parts are doing?  I'm not clear on what is actually happening here. > >  def initialize(blahblahblah) >     ........ >     self.class.add(self) >  end The part above invokes method #add on the class of this instance and passes self (i.e. the newly created object). >  self.add(cl) >    (@members ||= [])  << cl >  end This method adds cl (the instance passed from #initialize, "obj" would probably be a better argument name) to an Array stored in an instance variable of the class. The expression in brackets ensures the Array is set. A hint: usually it's pretty easy to try things in IRB and see what happens. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/