[英]Ruby: multidimensional %w array?
Could a multidimensional array be defined with a single %w
directive? 可以使用单个%w
指令定义多维数组吗?
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. 简写单词表示法的目的是用逗号和引号来保存所有标点符号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.