在ruby中创建这一系列数组的好方法是什么?

时间:2016-01-27 01:07:12

标签: arrays ruby

我有这个数组我正在创建一个选择框;然而,这绝对不是一个干净利落的方式。任何人都可以提供一种更简单的方法来写出来吗?

[ [ '0', '0' ],
  [ '1', '1' ],
  [ '2', '2' ],
  [ '3', '3' ],
  [ '4', '4' ],
  [ '5', '5' ],
  [ '6', '6' ],
  [ '7', '7' ],
  [ '8', '8' ],
  [ '9', '9' ],
  [ '10', '10' ],
  [ '11', '11' ],
  [ '12', '12' ],
  [ '13', '13' ],
  [ '14', '14' ],
  [ '15', '15' ],
  [ '16', '16' ],
  [ '17', '17' ],
  [ '18', '18' ],
  [ '19', '19' ],
  [ '20', '20' ],
  [ '21', '21' ],
  [ '22', '22' ],
  [ '23', '23' ] ]

1 个答案:

答案 0 :(得分:5)

Array.new(24){|i| [i.to_s, i.to_s]}