How to input a two-dimensional array in Ruby?How to initialize and declare the array in Ruby?
1 Answer
You declare a 2 dimensional array with
tda = [[ 1, 2 ], [3, 4], [5, 6]]
Or you can use the Matrix class
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/matrix/rdoc/Matrix.html
3 Comments
Sergio Tulentsev
This is called a jagged array in some languages (C#, at least), because it doesn't guarantee its rectangular "shape". At the same time, C# offers true 2d rectangular arrays. Just dumping my brain here. :)
pierallard
@SergioTulentsev That's why Ruby get us a beautiful
Matrix class :)Drew
I wouldn't necessarily call
Matrix a beautiful class; it's not even mutable.