簡體   English   中英

Ruby:多維%w數組?

[英]Ruby: multidimensional %w array?

可以使用單個%w指令定義多維數組嗎?

例如:

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

我需要這個來構建一個包含可變數量的項目的數組:

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

您可以執行反向操作,在標准數組括號中使用簡寫字數組表示法。

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

簡寫單詞表示法的目的是用逗號和引號來保存所有標點符號。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM