Sha256: 1a9f0f82483efa279e059cf6f357e864662fd7abfaa43dfe08f4887e2a196bd0

Contents?: true

Size: 538 Bytes

Versions: 12

Compression:

Stored size: 538 Bytes

Contents

# frozen_string_literal: true

module Refinements
  module Shared
    module Values
      # Provides shared whole value functionality for knowing the difference between two objects.
      module Diff
        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
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
refinements-12.6.0 lib/refinements/shared/values/diff.rb
refinements-12.5.0 lib/refinements/shared/values/diff.rb
refinements-12.4.0 lib/refinements/shared/values/diff.rb
refinements-12.3.0 lib/refinements/shared/values/diff.rb
refinements-12.2.0 lib/refinements/shared/values/diff.rb
refinements-12.1.0 lib/refinements/shared/values/diff.rb
refinements-12.0.1 lib/refinements/shared/values/diff.rb
refinements-12.0.0 lib/refinements/shared/values/diff.rb
refinements-11.1.3 lib/refinements/shared/values/diff.rb
refinements-11.1.2 lib/refinements/shared/values/diff.rb
refinements-11.1.1 lib/refinements/shared/values/diff.rb
refinements-11.1.0 lib/refinements/shared/values/diff.rb