Module: Hash::CorrectlyHashedHash

Defined in:
lib/erector/extensions/hash.rb

Instance Method Summary collapse

Instance Method Details

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/erector/extensions/hash.rb', line 13

def eql?(o)
  self == o
end

#hashObject



3
4
5
6
7
8
9
10
11
# File 'lib/erector/extensions/hash.rb', line 3

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