You can compare the output of your keys methods:
h1 = {one: 1, two: 2, three: 3} # => {:one=>1, :two=>2, :three=>3} h2 = {three: 3, one: 1, two: 2} # => {:three=>3, :one=>1, :two=>2} h1 == h2 # => true h1.keys # => [:one, :two, :three] h2.keys # => [:three, :one, :two] h1.keys.sort == h2.keys.sort # => true h1.keys == h2.keys # => false
But comparing hashes based on ordering key input is strange. Depending on what you are trying to do, you may want to revise your underlying data structure.
source share