Create two-dimensional arrays and access sub-arrays in Ruby

前端 未结 9 967
走了就别回头了
走了就别回头了 2020-11-28 03:26

I wonder if there\'s a possibility to create a two dimensional array and to quickly access any horizontal or vertical sub array in it?

I believe we can access a hor

9条回答
  •  温柔的废话
    2020-11-28 03:55

    Here is an easy way to create a "2D" array.

    2.1.1 :004 > m=Array.new(3,Array.new(3,true))
    
    => [[true, true, true], [true, true, true], [true, true, true]]
    

提交回复
热议问题