-
-
Save leejarvis/51aa9921ea38ce58e6ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'set' | |
class Foo | |
def initialize(name) | |
@name = name | |
end | |
def eql?(other) | |
self.hash == other.hash | |
end | |
def hash | |
@name.hash | |
end | |
end | |
set = Set.new | |
set << Foo.new('foo') | |
set << Foo.new('foo') | |
set << Foo.new('bar') | |
p set #=> #<Set: {#<Foo:0x00000100821698 @name="foo">, #<Foo:0x000001008215f8 @name="bar">}> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment