From: James Coglan Date: 2008-08-18T19:23:26+09:00 Subject: Re: Immutable, Interned strings?? ------=_Part_19427_25821629.1219055200763 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline > > What is the meaning of immutable, interned strings? > Would like to know in common, general English :-) Well, immutable means unchangeable. A String object can have its value changed: irb(main):001:0> s = "foo" => "foo" irb(main):002:0> s.object_id => -605872668 irb(main):003:0> s.hash => 876516207 irb(main):004:0> s.gsub! 'foo', 'bar' => "bar" irb(main):005:0> s => "bar" irb(main):006:0> s.object_id => -605872668 irb(main):007:0> s.hash => 841490416 You can see here that the object ID does not change, s is still the same String object. You cannot change the value of a Symbol in this way -- its value is fixed once the object is created. The 'hash' method is used by Hash objects to convert key objects to numbers, used to index the hashtable. The hash of an object generally depends on its properties, and two equal objects must have the same hash. Since the values of Symbols cannot change, neither can their hash codes. I think 'interned' has to do with the fact that, since Symbols never change, they are stored in a pool in memory and reused where possible. So, for example, all symbol literals :foo in a program all refer to the same Symbol object in memory, since there's no point creating additional, identical Symbols. ------=_Part_19427_25821629.1219055200763--