Altering array elements in place
Iterate using .map!
, .collect!
, if the index isn't something of interest:
[1, 2, 3, 4].map! do |element|
element * 2
end
Written by Melanie Archer
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#