class Unparser::Equalizer
Original code before vendoring and reduction from: github.com/dkubb/equalizer.
Define equality, equivalence and inspection methods
def define_cmp_method
def define_cmp_method keys = @keys define_method(:cmp?) do |comparator, other| keys.all? do |key| __send__(key).public_send(comparator, other.__send__(key)) end end private :cmp? end
def define_hash_method
def define_hash_method keys = @keys define_method(:hash) do keys.map(&public_method(:__send__)).push(self.class).hash end end
def define_inspect_method
def define_inspect_method keys = @keys define_method(:inspect) do klass = self.class name = klass.name || klass.inspect "#<#{name}#{keys.map { |key| " #{key}=#{__send__(key).inspect}" }.join}>" end end
def define_methods
def define_methods define_cmp_method define_hash_method define_inspect_method end
def included(descendant)
def included(descendant) descendant.include(Methods) end
def initialize(*keys)
- Api: - private
Returns:
-
(undefined)
-
Parameters:
-
keys
(Array
) --
def initialize(*keys) @keys = keys define_methods freeze end