I'm just learning Ruby, so I apologize if I'm too new here, but I can't figure it out from the pickax book (maybe just not reading it carefully enough). Anyway, if I have an array like this:
arr = [1,2,3,4,5]
... and I want, for example, to multiply each value in the array by 3, I developed the following:
arr.each {|item| item *= 3}
... will not get me what I want (and I understand why I am not modifying the array itself).
What I am not getting is how to change the original array from within the code block after the iterator. I am sure it is very easy.
arrays ruby iteration
brad Nov 21 '09 at 0:07 2009-11-21 00:07
source share