From: Brian Candler Date: 2012-09-20T16:48:45+09:00 Subject: Re: the behavior of iterator methods ten ten wrote in post #1076743: > irb(main):001:0> s = ["a", "b", "c"] > => ["a", "b", "c"] > irb(main):002:0> s[0].object_id > => 36971304 > irb(main):003:0> s[1].object_id > => 36971292 > irb(main):004:0> s[2].object_id > => 36971280 > irb(main):005:0> s.each{|c| c.upcase!} > => ["A", "B", "C"] > irb(main):006:0> p s > ["A", "B", "C"] > => nil It may be instructive to compare: s.each{|c| c << "X"} s.each{|c| c += "X"} The first mutates the object by adding a character to it. The second is short for c = c + "X"; it creates a new object from concatenating the two, and assigns the new object to local variable c. However it does not change the object which is still referenced from the array. -- Posted via http://www.ruby-forum.com/.