Sha256: 35b494fad3864d787199852a73cc5f1b6ff2ffb0f722222e40168c18777b9091

Contents?: true

Size: 601 Bytes

Versions: 10

Compression:

Stored size: 601 Bytes

Contents

# encoding: utf-8

module Nanoc3::HashExtensions

  # Returns a new hash where all keys are recursively converted into symbols.
  def symbolize_keys
    inject({}) do |hash, (key, value)|
      hash.merge(key.to_sym => value.respond_to?(:symbolize_keys) ? value.symbolize_keys : value)
    end
  end

  # Returns a new hash where all keys are recursively converted to strings.
  def stringify_keys
    inject({}) do |hash, (key, value)|
      hash.merge(key.to_s => value.respond_to?(:stringify_keys) ? value.stringify_keys : value)
    end
  end

end

class Hash
  include Nanoc3::HashExtensions
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
nanoc3-3.0.9 lib/nanoc3/base/core_ext/hash.rb
nanoc3-3.0.8 lib/nanoc3/base/core_ext/hash.rb
nanoc3-3.0.7 lib/nanoc3/base/core_ext/hash.rb
nanoc3-3.0.6 lib/nanoc3/base/core_ext/hash.rb
nanoc3-3.0.5 lib/nanoc3/base/core_ext/hash.rb
nanoc3-3.0.4 lib/nanoc3/base/core_ext/hash.rb
nanoc3-3.0.3 lib/nanoc3/base/core_ext/hash.rb
nanoc3-3.0.2 lib/nanoc3/base/core_ext/hash.rb
nanoc3-3.0.1 lib/nanoc3/base/core_ext/hash.rb
nanoc3-3.0.0 lib/nanoc3/base/core_ext/hash.rb