class Hash

Hash Class

Contains many convenient methods borred from Rails api.rubyonrails.org/classes/Hash.html

Public Instance Methods

deep_merge!(other_hash, &block) click to toggle source

Methods


deep_merge! method

Deep merges a hash into the current one. @param other_hash The hash to merge in @param &block @return Hash


# File lib/cliutils/ext/Hash+Extensions.rb, line 19
def deep_merge!(other_hash, &block)
  other_hash.each_pair do |k,v|
    tv = self[k]
    if tv.is_a?(Hash) && v.is_a?(Hash)
      self[k] = tv.deep_merge(v, &block)
    else
      self[k] = block && tv ? block.call(k, tv, v) : v
    end
  end
  self
end
deep_stringify_keys() click to toggle source

#deep_stringify_keys method

Recursively turns all Hash keys into strings and returns the new Hash. @return Hash


# File lib/cliutils/ext/Hash+Extensions.rb, line 38
def deep_stringify_keys
  deep_transform_keys{ |key| key.to_s }
end
deep_stringify_keys!() click to toggle source

#deep_symbolize_keys! method

Same as #deep_stringify_keys, but destructively alters the original Hash. @return Hash


# File lib/cliutils/ext/Hash+Extensions.rb, line 49
def deep_stringify_keys!
  deep_transform_keys!{ |key| key.to_s }
end
deep_symbolize_keys() click to toggle source

#deep_symbolize_keys method

Recursively turns all Hash keys into symbols and returns the new Hash. @return Hash


# File lib/cliutils/ext/Hash+Extensions.rb, line 60
def deep_symbolize_keys
  deep_transform_keys{ |key| key.to_sym rescue key }
end
deep_symbolize_keys!() click to toggle source

#deep_symbolize_keys! method

Same as #deep_symbolize_keys, but destructively alters the original Hash. @return Hash


# File lib/cliutils/ext/Hash+Extensions.rb, line 71
def deep_symbolize_keys!
  deep_transform_keys!{ |key| key.to_sym rescue key }
end
deep_transform_keys(&block) click to toggle source

#deep_transform_keys method

Generic method to perform recursive operations on a Hash. @return Hash


# File lib/cliutils/ext/Hash+Extensions.rb, line 82
def deep_transform_keys(&block)
  _deep_transform_keys_in_object(self, &block)
end
deep_transform_keys!(&block) click to toggle source

#deep_transform_keys! method

Same as #deep_transform_keys, but destructively alters the original Hash. @return Hash


# File lib/cliutils/ext/Hash+Extensions.rb, line 93
def deep_transform_keys!(&block)
  _deep_transform_keys_in_object!(self, &block)
end