How to initialize an array in one step using Ruby?

后端 未结 9 737
情话喂你
情话喂你 2021-01-30 00:08

I initialize an array this way:

array = Array.new
array << \'1\' << \'2\' << \'3\'

Is it possible to do that in one s

9条回答
  •  一向
    一向 (楼主)
    2021-01-30 00:24

    Along with the above answers , you can do this too

        =>  [*'1'.."5"]   #remember *
        => ["1", "2", "3", "4", "5"]
    

提交回复
热议问题