返回顶部

收藏

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

标签:Ruby,String

收藏

0人收藏

支持

0

反对

0

发表评论