module Refinements::Shared::Diff

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

Public Instance Methods

diff(other) click to toggle source
# 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