-2

How to input a two-dimensional array in Ruby?How to initialize and declare the array in Ruby?

0

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

3 Comments

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. :)
@SergioTulentsev That's why Ruby get us a beautiful Matrix class :)
I wouldn't necessarily call Matrix a beautiful class; it's not even mutable.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.