On Tue, Feb 12, 2013 at 2:06 PM, Joel P. [email protected]
wrote:
Robert K. wrote in post #1096452:
anybody can override header values or complete
rows / columns violating your class’s idea of internal state.This class only gets added into scripts, and I’m the only one who knows
Ruby where I work, so I don’t really see this being a problem yet.
I think you misunderstand OO. The point of OO is to build
abstractions of real world phenomena which behave in certain ways.
That does not have to do with how many people use the code; proper OO
abstractions help you even if you are the only one working with the
code because they encapsulate specific behavior and you as a user of
classes do not need to worry any longer about internals. By thinking
in proper abstractions you actually make your life easier since the
system is easier to understand.
I can rip the headers off data and also read my code back later and see
what it’s doing.
I would actually rather have Row and Colum as specific items which can
be asked for their header and iterate through all their values.
Example: Sample matrix with abstraction of rows and columns. This can certainly be improved, it's just to convey an idea. · GitHub
def filter( header, regex )
idx = self[0].index header
skip_headers { |xl| xl.select { |ar| ar[idx] =~ regex } }
end
That combines too much logic in one method IMHO. I’d rather select a
row based on header and then I would use #select on that.In this case, I’m filtering the data like Excel does. This means I’m
keeping all of the columns, but only specific rows based on the values
in a single column.
Right, and as I said I’d rather make that two separate steps. That is
much more modular and hence reusable.
So in short, my question is how can I return my class type after using
Array’s methods on my child-class?
Do you mean as return value from #map and the like? Well, you can’t
without overriding all methods with this approach, I’m afraid. That’s
one of the reasons why this approach does not work well.You’re probably thinking in terms of classes which are constantly active
as objects accessible to multiple users, whereas I’m just using this
class to make scripts easier to write.
See my initial statement: I think you are vastly underestimating the
value of OOP.
Cheers
robert