Sha256: f58d88d02513ac2651d74803653617955c4bf45b91029792b678e5a2d5b47c4e

Contents?: true

Size: 890 Bytes

Versions: 1

Compression:

Stored size: 890 Bytes

Contents

# frozen_string_literal: true

require 'forwardable'

module HashDeepDiff
  # This module includes behavior that is needed to use instances of Delta instead of Hash
  # in this gem
  module ActsAsHash
    # @param [Object] base a hook that is invoked when module is included in a class
    def self.included(base)
      base.extend Forwardable
      base.def_delegators :@delta, :==, :each_with_object, :each_key, :[],
                          :to_a, :empty?, :keys
      base.include InstanceMethods
    end

    # We assume that the class will initialize instance variable +@delta+ that will return
    # a representation of an instance of a class as a +Hash+ object
    module InstanceMethods
      # a +Hash+ representation of an object
      def to_h
        to_hash
      end

      # a +Hash+ representation of an object
      def to_hash
        @delta
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hash_deep_diff-0.5.0 lib/hash_deep_diff/acts_as_hash.rb