From: Stefano Mioli Date: 2011-07-16T03:50:46+09:00 Subject: Re: Comparing hashes based on their keys On 7/15/11 7:31 PM, Josh Cheek wrote: > Looks like you've probably got a bug. You explicitly return in your code, > causing it to stop evaluating after the first hash: [snip] Very true. This should work better. It still returns explicitly, but only if compare() itself returns false. def compare(hash1, hash2) args = [hash1, hash2] return true if args.all? {|h| h.nil?} return false if args.one? {|h| h.nil?} hash1.each_key do |k| values = [hash1[k], hash2[k]] if values.all? {|h| h.is_a?(Hash)} return false unless compare(*values) else return false if values.one? {|value| value.nil? } end end true end Thank you so much. -- Stefano Mioli