3

Could a multidimensional array be defined with a single %w directive?

For example:

the_array = %w(one two three{some separator}four five{some separator}six seven eight nine)

I need this to build an array with variable amount of items in a row:

the_array = [
    ['one', 'two', 'three'],
    ['four', 'five'],
    ['six', 'seven', 'eight', 'nine']
]

1 Answer 1

4

You can do the inverse, use the short-hand word array notation in a standard array brackets.

the_array = [%w(one two three), %w(four five), %w(six seven eight nine)]

The goal of the short-hand word notation is to save all the punctuation in terms of commas and quotation marks.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.