Sha256: fc0caaa266954406ab929527d9e448d29aefa49b9b2f80bc48d792062945ba03

Contents?: true

Size: 609 Bytes

Versions: 4

Compression:

Stored size: 609 Bytes

Contents

class Hash
  module CorrectlyHashedHash
    def hash
      out = 0
      # This sort_by is all kinds of weird...basically, we need a deterministic order here,
      # but we can't just use "sort", because keys aren't necessarily sortable (they don't
      # necessarily respond to <=>). Sorting by their hash codes works just as well, and
      # is guaranteed to work, since everything hashes.
      keys.sort_by { |k| k.hash }.each { |k| out ^= k.hash; out ^= self[k].hash }
      out
    end

    def eql?(o)
      self == o
    end
  end
  
  def correctly_hashed
    extend(CorrectlyHashedHash)
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
erector-0.8.2 lib/erector/extensions/hash.rb
honkster-erector-0.8.1 lib/erector/extensions/hash.rb
erector-0.8.1 lib/erector/extensions/hash.rb
erector-0.8.0 lib/erector/extensions/hash.rb