I don't understand why this isn't working. I've only been programming in ruby for a few months now but I feel like I at least know the basics, and this seems to me like it is basic. Why wont this each
iterator capitalize each element in the array? I feel like this should work, it feels like a no brainer. I feel like I have done things like this a million times before and they worked as intended, but for some reason this will not work? Is it something I am misunderstanding about how arrays work? I felt like that was the case, but when I do puts array[0].capitalize it capitalizes the element as intended. Why wont the each
iterator do the same? This is absolutely driving me nuts and is basically standing in the way of a larger project where I do something similar.
array = []
array << "apple"
array << "banana"
array << "peach"
array.each do |x|
x.capitalize
end
puts array #returns all non-capitalized words
puts array[0].capitalize #returns Apple...wtf why doesn't for loop work then?!?
puts "apple".capitalize #returns Apple as expected