Ordered hash hack for < ruby 1.9?

A

ara.t.howard

Thanks Erik, I agree 100%. I ONLY applied this when testing,

but that invalidates the tests ;-)
where
performance really isn't an issue. I just needed hashes to iterate
in a
consistent order. What was unique about my situation is that the hash
order didn't matter to the functional purpose of the method. It
mattered
only when I needed to do assertions in my tests.


Honestly, if order if meaningful you should use an array. I think
any of
the above gems are not the best choice when it comes to performance.


arrayfields gives you both - an array with hash access

a @ http://codeforpeople.com/
 
C

Charles Oliver Nutter

Ben said:
I am having an issue testing my code because hashes don't have a
consistent order when you iterate over them. For example, one of the
methods that I am trying to test iterates over a hash and creates a
string. That string is in a different order every time, and my tests
keep failing.

What would be perfect is if I could modify how the Hash class works so
it preserves the insert order, but only when I am testing. So I could
include this file in my tests.

Is there anything out there that does this? Thanks for your help.

FWIW, JRuby is 1.8.6ish and has insertion-ordered hashes like 1.9.

- Charlie
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top