File: stringify_keys.rb

package info (click to toggle)
ruby-fog-core 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 684 kB
  • sloc: ruby: 4,812; makefile: 5
file content (18 lines) | stat: -rw-r--r-- 487 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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

    # 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