people_names = ["Mike", "Tom", "Alison", "Jerry", "Cam"]
people_caps = people_names.each.upcase
# people_caps => ['MIKE', 'TOM', 'ALISON', 'JERRY', 'CAM']
我想將數組people_names中的每個項目都更改爲全部大寫。 我可以像這樣做:Ruby Array方法array.each.upcase
people_caps = people_names.each {|name| name.upcase!}
,但它也只是改變了people_names所有的帽子,但只有people_caps應該包含全大寫的名字,people_names應保持不變。