Sha256: 7d37e2fa1244aedb5b2960aaa913a98e0e532604641c91f56da148c0474adc0a

Contents?: true

Size: 551 Bytes

Versions: 2

Compression:

Stored size: 551 Bytes

Contents

# frozen_string_literal: true

module Micro
  module Attributes
    module Utils
      def self.stringify_hash_keys(arg)
        hash = Kind::Of.(::Hash, arg)

        return hash if hash.empty?

        if hash.respond_to?(:transform_keys)
          hash.transform_keys { |key| key.to_s }
        else
          hash.each_with_object({}) { |(key, val), memo| memo[key.to_s] = val }
        end
      end

      HashAccess = -> (hash, key) {
        return hash[key.to_s] unless hash[key.to_s].nil?

        hash[key.to_sym]
      }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
u-attributes-2.1.1 lib/micro/attributes/utils.rb
u-attributes-2.1.0 lib/micro/attributes/utils.rb