PATCH to make internal Hash class retain order...

H

Hal Fulton

Daniel said:
This is a question that has been raised during an earlier discussion of
this issue: What should this expression return?

{:foo => 1, :bar => 2} == {:bar => 2, :foo => 1}

I don't think there's any way around it returning `true', but that would
decrease the usefulness of ordered hashes. One solution would be that
Hash#== returns true in such cases while Hash#eql? returns false, just as

2 == 2.0 => true
2.eql? 2.0 => false

I once discussed this with Matz, and he said that two hashes
with the same key-value pairs would still be equal (if we
implemented an ordered hash, which is a big "if").

That doesn't bother me as long as I can iterate. I could
still do:

h1.to_a == h2.to_a

to check equality with order taken into account.


Hal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top