How can I turn an array of elements into uppercase? Expected output would be:
["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
=> ["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY"]
The following didn’t work and left them as lower case.
Day.weekday.map(&:name).each {|the_day| the_day.upcase }
=> ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
Return a New Array
If you want to return an uppercased array, use #map:
As you can see, the original array is not modified, but you can use the uppercased return value from #map anywhere you can use an expression.
Update Array in Place
If you want to uppercase the array in-place, use #map! instead: