Method: MIME::Type#hash
- Defined in:
- lib/mime/type.rb
#hash ⇒ Object
Returns a hash based on the #simplified value.
This maintains the invariant that two #eql? instances must have the same #hash (although having the same #hash does not imply that the objects are #eql?).
To see why, suppose a MIME::Type instance a is compared to another object b, and that a.eql?(b) is true. By the definition of #eql?, we know the following:
-
bis a MIME::Type instance itself. -
a == bis true.
Due to the first point, we know that b should respond to the #simplified method. Thus, per the definition of #<=>, we know that a.simplified must be equal to b.simplified, as compared by the <=> method corresponding to a.simplified.
Presumably, if a.simplified <=> b.simplified is 0, then a.simplified has the same hash as b.simplified. So we assume it is suitable for #hash to delegate to #simplified in service of the #eql? invariant.
266 267 268 |
# File 'lib/mime/type.rb', line 266 def hash simplified.hash end |