lib/equalizer.rb in equalizer-0.0.7 vs lib/equalizer.rb in equalizer-0.0.8

- old
+ new

@@ -14,16 +14,28 @@ # # @api private def initialize(*keys) @keys = keys define_methods - include_comparison_methods freeze end private + # Hook called when module is included + # + # @param [Module] descendant + # the module or class including Equalizer + # + # @return [self] + # + # @api private + def included(descendant) + super + descendant.module_eval { include Methods } + end + # Define the equalizer methods based on #keys # # @return [undefined] # # @api private @@ -39,11 +51,11 @@ # # @api private def define_cmp_method keys = @keys define_method(:cmp?) do |comparator, other| - keys.all? { |key| send(key).send(comparator, other.send(key)) } + keys.all? { |key| send(key).public_send(comparator, other.send(key)) } end private :cmp? end # Define a #hash method based on the instance's values identified by #keys @@ -68,18 +80,9 @@ define_method(:inspect) do || klass = self.class name = klass.name || klass.inspect "#<#{name}#{keys.map { |key| " #{key}=#{send(key).inspect}" }.join}>" end - end - - # Include the #eql? and #== methods - # - # @return [undefined] - # - # @api private - def include_comparison_methods - module_eval { include Methods } end # The comparison methods module Methods