On Wed, May 16, 2012 at 5:32 PM, Matt Mencel <[email protected]> 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/ -- You received this message because you are subscribed to the Google Groups ruby-talk-google group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at https://groups.google.com/d/forum/ruby-talk-google?hl=en
