When I run this, it correctly changes the 3
in array
to "blue"
, but it changes all other elements to nil
.
array = [1, 2, 3, 4]
array.map! do |number|
if number == 3
array[number] = "blue"
end
end
Since I introduced the if
statement, I expect it to leave everything else alone. Can someone explain why that's happening and how to get it to only modify the element isolated with the if
statement?