Class Index [+]

Quicksearch

DataMapper::Equalizer

Public Instance Methods

equalize(*methods) click to toggle source
   # File lib/dm-core/support/equalizer.rb, line 3
3:     def equalize(*methods)
4:       define_eql_method(methods)
5:       define_equivalent_method(methods)
6:       define_hash_method(methods)
7:     end

Private Instance Methods

define_eql_method(methods) click to toggle source
    # File lib/dm-core/support/equalizer.rb, line 11
11:     def define_eql_method(methods)
12:       class_eval         def eql?(other)          return true if equal?(other)          instance_of?(other.class) &&          #{methods.map { |method| "#{method}.eql?(other.#{method})" }.join(' && ')}        end, __FILE__, __LINE__ + 1
13:     end
define_equivalent_method(methods) click to toggle source
    # File lib/dm-core/support/equalizer.rb, line 21
21:     def define_equivalent_method(methods)
22:       respond_to = []
23:       equivalent = []
24: 
25:       methods.each do |method|
26:         respond_to << "other.respond_to?(#{method.inspect})"
27:         equivalent << "#{method} == other.#{method}"
28:       end
29: 
30:       class_eval         def ==(other)          return true if equal?(other)          return false unless kind_of?(other.class) || other.kind_of?(self.class)          #{respond_to.join(' && ')} &&          #{equivalent.join(' && ')}        end, __FILE__, __LINE__ + 1
31:     end
define_hash_method(methods) click to toggle source
    # File lib/dm-core/support/equalizer.rb, line 40
40:     def define_hash_method(methods)
41:       class_eval         def hash          self.class.hash ^ #{methods.map { |method| "#{method}.hash" }.join(' ^ ')}        end, __FILE__, __LINE__ + 1
42:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.