From: Love U Ruby Date: 2013-02-17T05:06:01+09:00 Subject: How the string concatenation operator hackes(modifies) the string contents of frozen array? Hi, Find the below code: >> b = %w[foo bar gis] => ["foo", "bar", "gis"] >> b.frozen? => false >> b.object_id => 7298560 >> b.freeze => ["foo", "bar", "gis"] >> b.object_id => 7298560 >> b[0] << "lish" => "foolish" >> b.object_id => 7298560 #How the "<<" operator made the change to the string where as being a concatenation operator "+" on string couldn't do that,rather prevented by the array? >> b[0]=b[0] + "lish" RuntimeError: can't modify frozen Array from (irb):16:in `[]=' from (irb):16 from /usr/bin/irb:12:in `
' -- Posted via http://www.ruby-forum.com/.