On Wed, Mar 13, 2013 at 6:18 PM, Joel Pearson <[email protected]> wrote: > Robert Klemme wrote in post #1101459:
>> I always find constructs like this suspicious: >> >> def cell( row, col ) >> Element.new( self, indices_to_address( row, col ) ) >> end >> >> The purpose of a constructor is to construct something and return it >> so the caller can do something with it. If you do not do that >> everybody is left wondering what happens to the newly created >> instance. If you need it only temporary then another method name >> would be better. Or change it so that not Element stores itself >> somewhere in "self" but rather "self" itself. > > I'm not really sure what you mean by this. My intention is that cell and > cells are like alises for range, but you can select by 1-based indices > (again, copying excel). Range is also capable of referring to more than > 1 cell, and can take cells as arguments. This allow for purely numerical > selection of any area, I've allowed columns to be selected numerically > as well. It's about the constructor (Element.new) - not addressing methods. Bottom line: don't abuse constructors for doing algorithmic things. Constructors are for constructing something so it is in a consistent state and can be worked with. Placing the complete logic in a constructor will prevent flexible use of classes. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ -- [email protected] | https://groups.google.com/d/forum/ruby-talk-google?hl=en --- You received this message because you are subscribed to the Google Groups "ruby-talk-google" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
