Sha256: d671c72c6c07dbe52ffa927b5d2fe83ae4d1cba7977a9da4b4d3ea9dd0c43d2a

Contents?: true

Size: 691 Bytes

Versions: 6

Compression:

Stored size: 691 Bytes

Contents

module JsonapiCompliable
  module Util
    class Hash
      def self.keys(hash, collection = [])
        hash.each_pair do |key, value|
          collection << key
          keys(value, collection)
        end

        collection
      end

      def self.deep_dup(hash)
        if hash.respond_to?(:deep_dup)
          hash.deep_dup
        else
          {}.tap do |duped|
            hash.each_pair do |key, value|
              value = deep_dup(value) if value.is_a?(Hash)
              value = value.dup if value && value.respond_to?(:dup) && ![Symbol, Fixnum].include?(value.class)
              duped[key] = value
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
jsonapi_compliable-0.5.7 lib/jsonapi_compliable/util/hash.rb
jsonapi_compliable-0.5.6 lib/jsonapi_compliable/util/hash.rb
jsonapi_compliable-0.5.5 lib/jsonapi_compliable/util/hash.rb
jsonapi_compliable-0.5.4 lib/jsonapi_compliable/util/hash.rb
jsonapi_compliable-0.5.3 lib/jsonapi_compliable/util/hash.rb
jsonapi_compliable-0.5.2 lib/jsonapi_compliable/util/hash.rb