class Hash
Public Instance Methods
_deep_transform_keys_in_object!(object) { |key| ... }
click to toggle source
# File lib/rack/tracker/extensions.rb, line 42 def _deep_transform_keys_in_object!(object, &block) case object when Hash object.keys.each do |key| value = object.delete(key) object[yield(key)] = _deep_transform_keys_in_object!(value, &block) end object when Array object.map! {|e| _deep_transform_keys_in_object!(e, &block)} else object end end
compact()
click to toggle source
# File lib/rack/tracker/extensions.rb, line 18 def compact select { |_, value| !value.nil? } end
deep_merge!(other_hash, &block)
click to toggle source
# File lib/rack/tracker/extensions.rb, line 22 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
NOTE Back ported from Rails 4 to 3 Destructively convert all keys to strings. This includes the keys from the root hash and from all nested hashes.
# File lib/rack/tracker/extensions.rb, line 61 def deep_stringify_keys! deep_transform_keys!{ |key| key.to_s } end
deep_transform_keys!(&block)
click to toggle source
NOTE Back ported from Rails 4 to 3 Destructively convert all keys by using the block operation. This includes the keys from the root hash and from all nested hashes.
# File lib/rack/tracker/extensions.rb, line 38 def deep_transform_keys!(&block) _deep_transform_keys_in_object!(self, &block) end
stringify_values()
click to toggle source
# File lib/rack/tracker/extensions.rb, line 11 def stringify_values inject({}) do |options, (key, value)| options[key] = value.to_s options end end