Sha256: 109bbe638bff05d21f02d8ead8a11b8b72888e00e771a7d86e6b26a824ab69fc

Contents?: true

Size: 342 Bytes

Versions: 12

Compression:

Stored size: 342 Bytes

Contents

class Hash

  # Destructively convert all keys which respond_to?(:to_sym) to symbols. Works recursively if given nested hashes.
  def symbolize_keys!
    each do |k,v|
      sym = k.respond_to?(:to_sym) ? k.to_sym : k
      self[sym] = Hash === v ? v.symbolize_keys! : v
      delete(k) unless k == sym
    end
    self
  end

end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
casualjim-caricature-0.5.0 lib/core_ext/hash.rb
casualjim-caricature-0.6.0 lib/core_ext/hash.rb
casualjim-caricature-0.6.1 lib/core_ext/hash.rb
caricature-0.7.6 lib/caricature/core_ext/hash.rb
caricature-0.7.5 lib/caricature/core_ext/hash.rb
caricature-0.7.2 lib/core_ext/hash.rb
caricature-0.7.1 lib/core_ext/hash.rb
caricature-0.7.0 lib/core_ext/hash.rb
caricature-0.6.3 lib/core_ext/hash.rb
caricature-0.6.0 lib/core_ext/hash.rb
caricature-0.5.0 lib/core_ext/hash.rb
caricature-0.6.1 lib/core_ext/hash.rb