Skip to content

Instantly share code, notes, and snippets.

@rsim
Created December 1, 2009 00:27
Show Gist options
  • Save rsim/245928 to your computer and use it in GitHub Desktop.
Save rsim/245928 to your computer and use it in GitHub Desktop.
def define_equivalent_method(methods)
respond_to = []
equivalent = []
methods.each do |method|
respond_to << "other.respond_to?(#{method.inspect})"
equivalent << "#{method} == other.#{method}"
end
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def ==(other)
return true if equal?(other)
result = #{respond_to.join(' && ')} &&
#{equivalent.join(' && ')}
result
end
RUBY
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment