3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/dm-core/support/equalizer.rb', line 3
def equalize(*methods)
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def eql?(other)
return true if equal?(other)
instance_of?(other.class) &&
#{methods.map { |method| "#{method}.eql?(other.#{method})" }.join(' && ')}
end
def ==(other)
return true if equal?(other)
#{methods.map { |method| "other.respond_to?(#{method.inspect})" }.join(' && ')} &&
#{methods.map { |method| "#{method} == other.#{method}" }.join(' && ')}
end
def hash
[ #{methods.join(', ')} ].hash
end
RUBY
end
|