you can convert an array on the fly using the collect method : collect « Array « Ruby






you can convert an array on the fly using the collect method


[1, 2, 3, 4].collect { |element| element * 2 }

 

Related examples in the same category

1.collect with code block
2.Change array elements with collect!