From: Robert Klemme Date: 2007-03-03T18:10:21+09:00 Subject: Re: Hash keys don't work as expected On 02.03.2007 23:37, Rick DeNatale wrote: Btw, there is an optimization going on under the hoods: unfrozen Strings are duped on onsertion: irb(main):006:0> k="xx" => "xx" irb(main):007:0> h={k=>1} => {"xx"=>1} irb(main):008:0> k.object_id => 1881810 irb(main):009:0> h.keys[0].object_id => 1881830 irb(main):010:0> k.freeze => "xx" irb(main):011:0> h={k=>1} => {"xx"=>1} irb(main):012:0> k.object_id => 1881810 irb(main):013:0> h.keys[0].object_id => 1881810 >> BTW. I try to avoid to mutate hash keys, I know my limits ;) > > Yes if you really want to be safe you can always clone and freeze keys > when inserting into a hash. But that's probably overkill. Cloning is not necessary for Strings (see above). Kind regards robert