Search code examples
rubyarraysenumerable

Apply method to each elements in array/enumerable


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)?


Solution

  • This will work:

    array.map!(&:to_s)