Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require "delegate"
Foo = Class.new(SimpleDelegator)
Bar = Struct.new(:foo)
Foo.new(1) == Foo.new(1) # => true
Bar.new(1) == Bar.new(1) # => true
Foo.new(Bar.new(1)) == Foo.new(Bar.new(1)) # => false
Baz = Class.new(SimpleDelegator) do
def ==(other)
return super(other.__getobj__) if self.class == other.class
super
end
end
Baz.new(Bar.new(1)) == Baz.new(Bar.new(1)) # => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.