Sha256: a734f1b15b3e105817a0f9e8870c8972638a89bce742747b86e6cc85950bc82e

Contents?: true

Size: 571 Bytes

Versions: 11

Compression:

Stored size: 571 Bytes

Contents

##
# Functions to convert hash keys to all symbols or all strings
##
class Hash
  def deep_symbolize! hsh = nil
    hsh ||= self
    hsh.keys.each do |k|
      if k.is_a? String
        hsh[k.to_sym] = hsh[k]
        hsh.delete k
      end
      deep_symbolize! hsh[k.to_sym] if hsh[k.to_sym].is_a? Hash
    end
    hsh
  end

  def deep_stringify! hsh = nil
    hsh ||= self
    hsh.keys.each do |k|
      if k.is_a? Symbol
        hsh[k.to_s] = hsh[k]
        hsh.delete k
      end
      deep_stringify! hsh[k.to_s] if hsh[k.to_s].is_a? Hash
    end
    hsh
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rbcli-0.1.10 lib/rbcli/util/hash_deep_symbolize.rb
rbcli-0.1.9 lib/rbcli/util/hash_deep_symbolize.rb
rbcli-0.1.8 lib/rbcli/util/hash_deep_symbolize.rb
rbcli-0.1.7 lib/rbcli/util/hash_deep_symbolize.rb
rbcli-0.1.6 lib/rbcli/util/hash_deep_symbolize.rb
rbcli-0.1.5 lib/rbcli/util/hash_deep_symbolize.rb
rbcli-0.1.4 lib/rbcli/util/hash_deep_symbolize.rb
rbcli-0.1.3 lib/rbcli/util/hash_deep_symbolize.rb
rbcli-0.1.2 lib/rbcli/util/hash_deep_symbolize.rb
rbcli-0.1.1 lib/rbcli/util/hash_deep_symbolize.rb
rbcli-0.1.0 lib/rbcli/util/hash_deep_symbolize.rb