Sha256: 8bfd8b4e89f3fcb190376861dd7501dd1c5233298b2c6bf17e94d3d5b9427be0

Contents?: true

Size: 645 Bytes

Versions: 1

Compression:

Stored size: 645 Bytes

Contents

# frozen_string_literal: true

module Lumberjack
  class Tags
    class << self
      # Transform hash keys to strings. This method exists for optimization and backward compatibility.
      # If a hash already has string keys, it will be returned as is.
      def stringify_keys(hash)
        return nil if hash.nil?
        if hash.keys.all? { |key| key.is_a?(String) }
          hash
        elsif hash.respond_to?(:transform_keys)
          hash.transform_keys(&:to_s)
        else
          copy = {}
          hash.each do |key, value|
            copy[key.to_s] = value
          end
          copy
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lumberjack-1.1.0 lib/lumberjack/tags.rb