On Sun, Feb 17, 2013 at 9:14 PM, Joel Pearson <[email protected]> wrote:
> I've attached my attempt at converting your code to suit mine (hope you
> don't mind the plagarism :p )
No, it's not a doctoral thesis. :-) (allusion to German politics)
> I have a list of some of my plans to add functionality at the top, and
> I've rewritten your test at the bottom to suit the new options.
>
> I'd be interested to know whether there are any things I'm doing
> drastically wrong... I think the rows? and columns? might be able to be
> done more succinctly, for example.
First of all their names seem weird. Methods with a question mark at
the end are usually intended to be used in a boolean context. But
rows? and columns? return the row and column counts. Plus, they do
not gracefully deal with an empty Matrix. I guess for everyday use it
will be more efficient to store max values in two members because you
will need them often for iteration.
Method #array could use Columns's #map method. If you rewrite
iteration methods like this
def each_row
return to_enum(:each_row) unless block_given?
(1..rows?).each do |idx|
yield row( idx )
end
self
end
Then you can even do
def array
each_row.map do |row|
row.to_a
end
end
And I would consider changing []= to actually remove the entry if the
value is nil. (Excel does it differently, I believe. It will not
reduce the area it considers "used" when emptying the last cell in the
last column or row.)
Ah, and I would add a validity check for addresses - otherwise one can
get any String into the Hash as key - even things which are not valid
addresses.
But generally I think you get the hang of it.
Kind regards
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.