Greetings!
When assigning a value to an array as in the following, how could I replace the nil
s by 0
?
array = [1,2,3]
array[10] = 2
array # => [1, 2, 3, nil, nil, nil, nil, nil, nil, nil, 2]
If not possible when assigning, how would I do it the best way afterwards? I thought of array.map { |e| e.nil? ? 0 : e }
, but well…
Thanks!