From: Robert Klemme Date: 2004-04-16T18:29:12+09:00 Subject: Re: Hash, ==, key-value comparison "Florian Gross" schrieb im Newsbeitrag news:c5mvnb$3ktu5$1@ID-7468.news.uni-berlin.de... > walter@mwsewall.com wrote: > > This will work: .... and burn a lot of mem if both hashes are huge. Regards robert > irb(main):001:0> class Hash > irb(main):002:1> def equal_content?(other) > irb(main):003:2> {}.update(self) == {}.update(other) > irb(main):004:2> end > irb(main):005:1> end > => nil > irb(main):006:0> hash_a = Hash.new { |h, k| h[k] = rand } > => {} > irb(main):007:0> hash_a[:foo] = "bar" > => "bar" > irb(main):008:0> hash_a[:qux] = "quz" > => "quz" > irb(main):009:0> hash_b = {:foo => "bar", :qux => "quz"} > => {:foo=>"bar", :qux=>"quz"} > irb(main):010:0> hash_a.equal_content?(hash_b) > => true > irb(main):011:0> {}.equal_content?(:x => 1) > => false > > Regards, > Florian Gross