As Ruby On Rails Developer , I need to update all element in an array to be zero. So the array will be [0,0,0,0]. But instead of getting an array like that, I end up with [nil,nil,nil,nil]. Now the question is how to update all element in an array in Ruby On Rails? Here's the simple and worked answer:
To update all element in an array , we only need to change "each" into "map". So, our Rails code should be like this one:
arr.map {|x| x=0 }
This is the proof that this way worked at least for me. I use Ruby 1.8.7 with Rails 2.8.7. I think it would work with the newer version too.
It's really simple, isn't it ?