From: James Coglan Date: 2008-08-18T19:35:07+09:00 Subject: Re: The symbol dilemma... ------=_Part_19593_9913831.1219055905103 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline > > > Can't I do the following? > > books = { > > :excellent => "Iacocca", > > :good => "Freakonomics", > > :bad => "The World is Flat", > > :ugly => "Guns, Germs and Steel", > > :sick => "Guns, Germs and Steel" > > } > > > > In that case, won't two distinct Symbol objects, i.e. :ugly, and :sick > > have the same content? > > > > I'm sure there's something wrong in the way I'm understanding this, > > could someone please elaborate? > > The symbols themselvs (:ugly and :sick) will always be distinct, not > the strings they act as keys for in the hash. More precisely, symbols with same value are shared and point to the same objects in memory: > syms = [:foo, :bar, :baz, :foo, :baz] > syms.map { |s| s.object_id } => [148818, 161538, 161618, 148818, 161618] So, if two symbols have the same value, they are actually the very same object in memory. Therefore, two distinct Symbol objects must have different values. ------=_Part_19593_9913831.1219055905103--