From: Robert Klemme Date: 2003-10-06T22:21:40+09:00 Subject: Re: compare two identically hashes fails "Simon Strandgaard" schrieb im Newsbeitrag news:pan.2003.10.06.13.17.01.151417@sneakemail.com... > On Mon, 06 Oct 2003 15:59:59 +0200, Simon Strandgaard wrote: > > > On Mon, 06 Oct 2003 15:52:59 +0200, Simon Strandgaard wrote: > > > >> failure 1).. I compare 2 hashes with assert_equal. > >> If I inspect the hashes they appear to be identical. > >> But the == operator tells me they are different??? > >> I only use Ruby's native types for the things stored in > >> the hash. Question: Why does this assertion fail ? > > > > > > I have found a simplification of my problem: > > > > def test_hash_compare > > on_new = proc {|h, k| h[k] = []} > > h1 = Hash.new(&on_new) > > h1[1] = [["a", 2]] > > h1[2] = [] > > h2 = {1=>[["a", 2]], 2=>[]} > > h1.default = nil > h2.default = nil > > > > assert_equal(h1, h2) > > end > > > > How should I compare these 2 hashes, so it yields true ? > > Now it yields true.. thanks comp.lang.ruby :-) You're welcome. Sometimes expressing one's thoughts is already enough to find the answer. :-) Have fun robert