On 11/10/05, Peter v. N. <skull2crush / hotmail.com> wrote:
> Hi all,
>
> I'm a Ruby noob so please forgive me...
>
> I know there exist "simple" ways (Google's thy friend)
> to create md arrays with Ruby. But it's somehow cumbersome
> and it would be nice if it could be done like "array = Array.new(3,3)"
> -> I know too that this means not the same in Ruby...
>
> What I like to know: what led to the decission to do it that way
> and not like it is done in the C/C++ (Java) languages ? la
> "int[][] arr = new int[3][3]"?

you do it the same as in c, you say that you want an array of arrays.
E.g.

arr = Array.new(3) { Array.new(3) }

which is the same as int[3][3] in c where iirc int[3][3] is not a
contiguous block of memory but pointers to arrays. If you want a
contiguous block of memory maybe narray can help you.

>
> Maybe because this approach is not strictly oo-oriented? But then,
> switches and loops in Ruby are neither.

In my opinion this has nothing to do with oo versus non oo. Switches
and loops are signs of imperative programming, which is oppsite to
functional and logical programming but orthogonal to object oriented
versus not object oriented.

>
> It's just the devil inside who likes to know about the philosophy
> about the "why it is done like that" and I'm not bitching about
> Ruby (by no means).
>
> Thank you for a pointer or a short explanation.
>
> Greetings,
> Peter
>
>

And beware that
Array.new(3, Array.new(3)) is not the same as Array.new(3) { Array.new(3) }

hope to help,

Brian

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/