Sha256: 3ade91fb3212df58b40b816bd303e47bc1f015d6384b325d824e8e51341dcc0a

Contents?: true

Size: 576 Bytes

Versions: 12

Compression:

Stored size: 576 Bytes

Contents

module Propono
  module Utils

    # Returns +hash+ with all primary and nested keys to string values symbolised
    # To avoid conflicts with ActiveSupport and other libraries that provide Hash symbolisation,
    # this method is kept within the Propono namespace and not mixed into Hash
    def self.symbolize_keys(hash)
      hash.inject({}) do |result, (key, value)|
        new_key = key.is_a?(String) ? key.to_sym : key
        new_value = value.is_a?(Hash) ? symbolize_keys(value) : value
        result[new_key] = new_value
        result
      end
    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
propono-3.0.0 lib/propono/utils.rb
propono-2.2.1 lib/propono/utils.rb
propono-2.2.0 lib/propono/utils.rb
propono-2.1.0 lib/propono/utils.rb
propono-2.0.0 lib/propono/utils.rb
propono-2.0.0.rc3 lib/propono/utils.rb
propono-2.0.0.rc2 lib/propono/utils.rb
propono-2.0.0.rc1 lib/propono/utils.rb
propono-1.7.0 lib/propono/utils.rb
propono-1.6.0 lib/propono/utils.rb
propono-1.5.0 lib/propono/utils.rb
propono-1.4.0 lib/propono/utils.rb