Module: Refinements::Shared::Values::Diff

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

Overview

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

Instance Method Summary collapse

Instance Method Details

#diff(other) ⇒ Object



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

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