Apply method to each elements in array/enumerable

Vladimir Tsukanov picture Vladimir Tsukanov · Jun 27, 2011 · Viewed 41.1k times · Source

This is my array:

array = [:one,:two,:three]

I want to apply to_s method to all of my array elements to get array = ['one','two','three'].

How can I do this (converting each element of the enumerable to something else)?

Answer

sawa picture sawa · Jun 27, 2011

This will work:

array.map!(&:to_s)