Change array elements with collect! : collect « Array « Ruby






Change array elements with collect!


array = ['a', 'b', 'c']
array.collect! { |x| x.upcase }
p array                               # => ["A", "B", "C"]

 








Related examples in the same category

1.you can convert an array on the fly using the collect method
2.collect with code block