3 ms·
> Create a subclass called NumberArray that can only hold numbers and has specific methods for operating on them. I can't see anything wrong with this for some
by raganwald 18y ago
> Create a subclass called NumberArray that can only hold numbers and has specific methods for operating on them.
I can't see anything wrong with this for some cases. Another way to get there would be to define a NumericCollection module that can be used to extend any Array.
- tjstankus 18y agoI would tend toward that idea: a module that can be included. Injecting a sum method into the object's ghost class also maintains scope of responsibility, but feels a bit more magic. I'd opt for less magic. At first, anyway. :)
- omouse 18y agoHow about create a method called detectSum that accepts a block as an argument. The block will return the specific field to use when summing. This lets you skip subclassing.