Class: Lumberjack::Tags

Inherits:
Object
  • Object
show all
Defined in:
lib/lumberjack/tags.rb

Class Method Summary collapse

Class Method Details

.stringify_keys(hash) ⇒ Object

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.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/lumberjack/tags.rb', line 8

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