ruby - How can I uppercase each element of an array? -


How do I change the array of elements in uppercase? The expected output will be:

  ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"] => ["Monday", "Today", "Wednesday", "Thursday", "Friday"]   

did the following and left them as a short case. Day. Wax.map (& amp;: name) .each {| The_day | The_day.upcase} = & gt; ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]

return a new array

If you want to return the uppercase array, use #map :

  array = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"] # Return the upper version back to the array.map (and: up to) = & gt; ["Monday", "Thursday", "Wednesday", "Thursday", "Friday"] #Remove Unassisted Array = Array = & gt; As you can see, the original array is not modified, but you can see the upper part of [ You can use the return value from #map anywhere you can use an expression.  

Update Array to Place

If you want an uppercase array, press #map! ; ["Monday", "Today", "Wednesday", "Thursday", "Friday"]

Comments