Sha256: 10043814fb8d9ea83491e8b2f0e203d4f3cd5369f1bbd80b6aec848d8cf51752

Contents?: true

Size: 500 Bytes

Versions: 25

Compression:

Stored size: 500 Bytes

Contents

module Fog
  module StringifyKeys
    # Returns a new hash with all keys converted to strings.
    def self.stringify(original_hash)
      transform_hash(original_hash) do |hash, key, value|
        hash[key.to_s] = value
      end
    end

    private

    # http://devblog.avdi.org/2009/11/20/hash-transforms-in-ruby/
    def self.transform_hash(original, &block)
      original.reduce({}) do |result, (key, value)|
        block.call(result, key, value)
        result
      end
    end
  end
end

Version data entries

25 entries across 22 versions & 2 rubygems

Version Path
fog-core-2.3.0 lib/fog/core/stringify_keys.rb
fog-core-2.2.4 lib/fog/core/stringify_keys.rb
fog-core-2.2.3 lib/fog/core/stringify_keys.rb
fog-core-2.2.2 lib/fog/core/stringify_keys.rb
fog-core-2.2.1 lib/fog/core/stringify_keys.rb
fog-core-2.2.0 lib/fog/core/stringify_keys.rb
fog-core-2.1.2 lib/fog/core/stringify_keys.rb
fog-core-2.1.1 lib/fog/core/stringify_keys.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-core-1.45.0/lib/fog/core/stringify_keys.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-core-1.45.0/lib/fog/core/stringify_keys.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-core-2.1.0/lib/fog/core/stringify_keys.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-core-1.45.0/lib/fog/core/stringify_keys.rb
fog-core-2.1.0 lib/fog/core/stringify_keys.rb
fog-core-2.0.0 lib/fog/core/stringify_keys.rb
fog-core-1.45.0 lib/fog/core/stringify_keys.rb
fog-core-1.44.3 lib/fog/core/stringify_keys.rb
fog-core-1.44.2 lib/fog/core/stringify_keys.rb
fog-core-1.44.1 lib/fog/core/stringify_keys.rb
fog-core-1.44.0 lib/fog/core/stringify_keys.rb
fog-core-1.43.0 lib/fog/core/stringify_keys.rb