Class: Virtus::ValueObject::Equalizer

Inherits:
Module
  • Object
show all
Defined in:
lib/virtus/value_object/equalizer.rb

Overview

A type of Module for dynamically defining and hosting equality methods

Instance Method Summary collapse

Constructor Details

#initialize(host_name, keys = []) ⇒ Equalizer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize an Equalizer with the given keys

Will use the keys with which it is initialized to define #eql?, #==,

and #hash


13
14
15
# File 'lib/virtus/value_object/equalizer.rb', line 13

def initialize(host_name, keys = [])
  @host_name, @keys = host_name, keys
end

Instance Method Details

#<<(key) ⇒ Equalizer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Append a key and compile the equality methods

Returns:



22
23
24
25
# File 'lib/virtus/value_object/equalizer.rb', line 22

def <<(key)
  @keys << key
  compile
end

#compileself

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Compile the equalizer methods based on #keys

Returns:

  • (self)


32
33
34
35
36
37
38
# File 'lib/virtus/value_object/equalizer.rb', line 32

def compile
  define_inspect_method
  define_eql_method
  define_equivalent_method
  define_hash_method
  self
end