Sha256: 9ea75879da0d529f4d42e2c33b0fad38ae9fcb171271e9d5444bf72643770777

Contents?: true

Size: 665 Bytes

Versions: 2

Compression:

Stored size: 665 Bytes

Contents

module Fog
  module StringifyKeys

    # Returns a new hash with all keys converted to strings.
    def self.stringify(hash)
      self.transform_hash(hash) {|hash, key, value|
        hash[key.to_s] = value
      }
    end

    private

    # http://devblog.avdi.org/2009/11/20/hash-transforms-in-ruby/
    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

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fog-core-1.24.0 lib/fog/core/stringify_keys.rb
fog-core-1.23.0 lib/fog/core/stringify_keys.rb