require 'minitest/autorun' require 'set' class Foo def initialize(s) @s = s end def ==(other) @s == other end def eql?(other) @s.eql?(other) end def hash @s.hash end end module FooEquality def ==(other) if other.is_a?(Foo) other == self else super(other) end end def eql?(other) if other.is_a?(Foo) other.eql?(self) else super(other) end end end class String prepend FooEquality end class TestSet < MiniTest::Unit::TestCase def setup @foo = Foo.new("foo") @set = Set.new([@foo]) @hsh = { @foo => true } end def test_set_include_obj assert @set.include?(@foo) end def test_set_include_str assert @set.include?("foo") end def test_hsh_include_obj assert @hsh.include?(@foo) end def test_hsh_include_str assert @hsh.include?("foo") end def test_eql assert @foo.eql?("foo") end def test_hash assert @foo.hash == "foo".hash end end