Class: Virtus::Equalizer

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

Overview

Define equality, equivalence and inspection methods

Defined Under Namespace

Modules: Methods

Instance Method Summary collapse

Constructor Details

#initialize(name, keys = []) ⇒ undefined

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 #cmp?, #hash, and #inspect

Parameters:

  • name (String)
  • keys (Array<Symbol>) (defaults to: [])


18
19
20
21
22
23
# File 'lib/virtus/support/equalizer.rb', line 18

def initialize(name, keys = [])
  @name = name.dup.freeze
  @keys = keys.dup
  define_methods
  include_comparison_methods
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:



30
31
32
33
# File 'lib/virtus/support/equalizer.rb', line 30

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