String hash value : hash value « String « Ruby






String hash value


class StringHolder
  attr_reader :string
  def initialize(s)
    @string = s
  end

  def ==(other)
    @string == other.string
  end

  def hash
    @string.hash
  end
end
a = StringHolder.new("The same string.")
b = StringHolder.new("The same string.")
a == b                                                      # => true
a.hash                                                      # => -1007666862
b.hash                                                      # => -1007666862

 








Related examples in the same category