Answers for "%w to create a array in rails"

1

how to make a new array ruby

my_array = []
# OR
my_array = [1, 2, 3]
# OR
my_array = Array.new
#OR
(1..10).to_a
Posted by: Guest on June-11-2020
1

Ruby Array.new syntax

Array.new( number of indices, value of the indices ) { optional block for value of indices }

ary = Array.new    #=> []
Array.new(3)       #=> [nil, nil, nil]
Array.new(3, true) #=> [true, true, true]
Array.new(3) { Hash.new } #=> [ {}, {}, {} ]
Posted by: Guest on February-07-2020

Browse Popular Code Answers by Language