Skip to content
instance method

Struct#hash

() -> ::Integer
hash → integer

Returns the integer hash value for self.

Two structs of the same class and with the same content will have the same hash code (and will compare using Struct#eql?):

Example
Customer = Struct.new(:name, :address, :zip)
joe    = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
joe_jr = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
joe.hash == joe_jr.hash # => true
joe_jr[:name] = 'Joe Smith, Jr.'
joe.hash == joe_jr.hash # => false

Related: Object#hash.

See also #filter #inspect #eql? #length also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0