简体   繁体   中英

Ruby: multidimensional %w array?

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']
]

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM