module Fog::StringifyKeys

Public Class Methods

stringify(hash) click to toggle source

Returns a new hash with all keys converted to strings.

# File lib/fog/core/stringify_keys.rb, line 5
def self.stringify(hash)
  self.transform_hash(hash) {|hash, key, value|
    hash[key.to_s] = value
  }
end

Private Class Methods

transform_hash(original, options={}, &block) click to toggle source

devblog.avdi.org/2009/11/20/hash-transforms-in-ruby/

# File lib/fog/core/stringify_keys.rb, line 14
def self.transform_hash(original, options={}, &block)
  original.inject({}){|result, (key,value)|
    value = if (options[:deep] && Hash === value)
              transform_hash(value, options, &block)
            else
              value
            end
    block.call(result,key,value)
    result
  }
end