Skip to content

Instantly share code, notes, and snippets.

@soulcutter
Created December 29, 2016 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soulcutter/ad665846973956826c9c39d4af65c640 to your computer and use it in GitHub Desktop.
Save soulcutter/ad665846973956826c9c39d4af65c640 to your computer and use it in GitHub Desktop.
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