ibanez270dx
10/27/2015 - 6:58 PM

Turn a hash into a sorted array of strings in order to compare to another hash

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