Module: Refinements::Shared::Diff

Defined in:
lib/refinements/shared/diff.rb

Overview

Provides functionality for knowing the difference between two whole value objects.

Instance Method Summary collapse

Instance Method Details

#diff(other) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/refinements/shared/diff.rb', line 7

def diff other
  if other.is_a? self.class
    to_h.merge(other.to_h) { |_, one, two| [one, two].uniq }
        .select { |_, diff| diff.size == 2 }
  else
    to_h.each.with_object({}) { |(key, value), diff| diff[key] = [value, nil] }
  end
end