Which equality test does Ruby's Hash use when comparing keys?
问题 I have a wrapper class around some objects that I want to use as keys in a Hash. The wrapped and unwrapper objects should map to the same key. A simple example will be this: class A attr_reader :x def initialize(inner) @inner=inner end def x; @inner.x; end def ==(other) @inner.x==other.x end end a = A.new(o) #o is just any object that allows o.x b = A.new(o) h = {a=>5} p h[a] #5 p h[b] #nil, should be 5 p h[o] #nil, should be 5 I've tried ==, ===, eq? and hash all to no avail. 回答1: Hash uses