Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created July 26, 2014 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save havenwood/80f2724eccd35a65257c to your computer and use it in GitHub Desktop.
Save havenwood/80f2724eccd35a65257c to your computer and use it in GitHub Desktop.
An EqualizableStruct with Equalizer
require 'equalizer'
class EqualizableStruct < Struct
def initialize *args, &block
class << self
include Equalizer.new(*members)
end
super
end
end
Point = EqualizableStruct.new(:x, :y)
Point.new(0, 0) == Point.new(0, 0)
#=> true
Point.new(0, 0) == Point.new(1, 1)
#=> false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment