Array initialized by copying : Array.new « Array « Ruby






Array initialized by copying


squares = Array.new(5) {|i| i*i}
copy = Array.new(squares) # initialized by copying
p squares[5] = 25

 








Related examples in the same category

1.Array with Array.new
2.Array.new creates an empty array
3.Array.new(2) creates an array with two nil values
4.Array.new(5, "A") fills an array with five a
5.Create an array of hashes
6.Fill an array of hashes