From: Sean O'Halpin Date: 2006-07-23T21:09:21+09:00 Subject: Re: Symbols vs. strings as hash_keys - interchangeable or not? On 7/22/06, transfire@gmail.com wrote: > As Ezra points out they are not the same in Ruby. A hash key can be any > object whatsoever. It could even be a number or another hash: > > { {:a=>1} => 'yep' } > Not meaning to be picky ;) but your example is a bit misleading. Consider: h1 = { {:a => 1} => 'nope'} p h1[{:a => 1}] #=> nil hk = {:a => 1} h2 = {hk => 'yep'} p h2[hk] #=> "yep" The problems of using hashes as keys has come up a few times - see e.g. ruby-talk:167185 for one solution. Or you could just use: class Hash def hash self.to_a.hash end def eql?(other) hash == other.hash end end h = {{ :a => 1, :b => 2 } => 'yep'} p h[:a => 1, :b => 2] #=> "yep" though to be honest I'm not sure if this has unpleasant side-effects on any libs. Regards, Sean