intridea/hashie — pull request #42 by jeremyruppel (2012-04-03 16:45:32+00:00)
Title: LenientEquality extension

I was testing an API recently and had this idea for a little hash extension that would allow me to only test parts of the response structure that I cared about. Figured it might be able to find a nice home in hashie.

The gist is that a leniently-equal hash will match another hash if the lenient hash is a subset of the other hash. It overrides the `eql?` method, but that's it, so you could still determine stricter equality if you wanted. So for example:

class MyHash < ::Hash
include Hashie::Extensions::MergeInitializer
include Hashie::Extensions::LenientEquality
end

h = MyHash.new :foo => 'bar'
h.eql?( {:baz => 'qux', :foo => 'bar'} ) # => true

A lenient hash also considers the order of nested arrays and hashes to be unimportant when determining equality.

Let me know what you think. Thanks!