Skip to content

Instantly share code, notes, and snippets.

@ibanez270dx
Last active October 28, 2015 13:43
Show Gist options
  • Save ibanez270dx/944047f843cd6694986b to your computer and use it in GitHub Desktop.
Save ibanez270dx/944047f843cd6694986b to your computer and use it in GitHub Desktop.
Turn a hash into a sorted array of strings in order to compare to another hash
def deflate(hash)
hash.collect do |k,v|
[k.to_s].push v.is_a?(Hash) ? v.to_a.flatten : v
end.flatten.collect(&:to_s).sort
end
event1 = { foo: 'bar', bars: [4,6,10] }
event2 = { bars: [10,4,6], foo: 'bar' }
event1 == event2
# => false
deflate(event1) == deflate(event2)
# => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment