Hello --

On Fri, 27 Jul 2001, Joseph McDonald wrote:

> DAB> Anyway, for your hacking pleasure, here is a Matrix-based rewrite.
> DAB> Note that creating a matrix involves a call to #[] -- for example,
> DAB> m = Matrix[ [1,2], [3,4] ].)
>
> Here's my version, perhaps not as good as the matrix version, but more
> understandable to me:

The matrix version works like this: It starts with a matrix with the
words in rows/columns.  It then makes a new matrix (well, actually an
array), whose rows are the original matrix's columns and vice versa.
It does that so that it can do the padding for each column.  (A
padding method is added to class Array for this purpose.)  The result
is that everything's padded correctly, but the matrix is transposed as
to rows and columns.  So it gets transposed back and #join'ed
together.

> class StringTable < Array
>   def to_s
[...]
>   puts StringTable[*lst].to_s
> end
>
> test1
>
> ==================
> One thing weird though... I have to:
>   puts StringTable[*lst].to_s
> instead of just:
>   puts StringTable[*lst]

You can use print, but still it is surprising to learn that overriding
#to_s doesn't change the string representation of Array or its
subclasses (as seen by puts anyway).


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav