class Hash
Public Instance Methods
deep_dup()
click to toggle source
# File lib/leap_cli/core_ext/deep_dup.rb, line 10 def deep_dup each_with_object(dup) do |(key, value), hash| hash[key.deep_dup] = value.deep_dup end end
deep_merge(other_hash)
click to toggle source
recursive merging (aka deep merge) taken from ActiveSupport::CoreExtensions::Hash::DeepMerge
# File lib/leap_cli/core_ext/hash.rb, line 23 def deep_merge(other_hash) self.merge(other_hash) do |key, oldval, newval| oldval = oldval.to_hash if oldval.respond_to?(:to_hash) newval = newval.to_hash if newval.respond_to?(:to_hash) oldval.class.to_s == 'Hash' && newval.class.to_s == 'Hash' ? oldval.deep_merge(newval) : newval end end
deep_merge!(other_hash)
click to toggle source
# File lib/leap_cli/core_ext/hash.rb, line 31 def deep_merge!(other_hash) replace(deep_merge(other_hash)) end
pick(*keys)
click to toggle source
convert self into a hash, but only include the specified keys
# File lib/leap_cli/core_ext/hash.rb, line 10 def pick(*keys) keys.map(&:to_s).inject({}) do |hsh, key| if has_key?(key) hsh[key] = self[key] end hsh end end
symbolize_keys()
click to toggle source
# File lib/leap_cli/core_ext/hash.rb, line 39 def symbolize_keys self.inject({}) {|result, (key, value)| new_key = case key when String then key.to_sym else key end new_value = case value when Hash then symbolize_keys(value) else value end result[new_key] = new_value result } end