Created
December 1, 2009 00:27
-
-
Save rsim/245928 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
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