Class: WebMock::Util::HashKeysStringifier

Inherits:
Object
  • Object
show all
Defined in:
lib/webmock/util/hash_keys_stringifier.rb

Class Method Summary collapse

Class Method Details

.stringify_keys!(arg, options = {}) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/webmock/util/hash_keys_stringifier.rb', line 5

def self.stringify_keys!(arg, options = {})
  case arg
  when Array
    arg.map { |elem|
      options[:deep] ? stringify_keys!(elem, options) : elem
    }
  when Hash
    Hash[
      *arg.map { |key, value|
        k = key.is_a?(Symbol) ? key.to_s : key
        v = (options[:deep] ? stringify_keys!(value, options) : value)
        [k,v]
      }.inject([]) {|r,x| r + x}]
  else
    arg
  end
end