Sha256: 88a0673792de8d667d6c278635018c9526c9a63ec4599820684e946b5e314f95

Contents?: true

Size: 578 Bytes

Versions: 10

Compression:

Stored size: 578 Bytes

Contents

# frozen_string_literal: true

# Hash helpers
class ::Hash
  ##
  ## Destructive version of #symbolize_keys
  ##
  ## @see        #symbolize_keys
  ##
  ## @return     [Hash] hash with keys as symbols
  ##
  def symbolize_keys!
    replace symbolize_keys
  end

  ##
  ## Convert all keys in hash to symbols. Works on nested hashes
  ##
  ## @see        #symbolize_keys!
  ##
  ## @return     [Hash] hash with keys as symbols
  ##
  def symbolize_keys
    each_with_object({}) { |(k, v), hsh| hsh[k.to_sym] = (v.is_a?(Hash) || v.is_a?(Array)) ? v.symbolize_keys : v }
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
marked-conductor-1.0.39 lib/conductor/hash.rb
marked-conductor-1.0.38 lib/conductor/hash.rb
marked-conductor-1.0.37 lib/conductor/hash.rb
marked-conductor-1.0.35 lib/conductor/hash.rb
marked-conductor-1.0.33 lib/conductor/hash.rb
marked-conductor-1.0.32 lib/conductor/hash.rb
marked-conductor-1.0.31 lib/conductor/hash.rb
marked-conductor-1.0.30 lib/conductor/hash.rb
marked-conductor-1.0.29 lib/conductor/hash.rb
marked-conductor-1.0.28 lib/conductor/hash.rb