brew vendor-gems: commit updates.
This commit is contained in:
parent
a87cdf0d21
commit
14f8a086d8
@ -16,9 +16,7 @@ class Hash
|
|||||||
# h2 = { b: 250, c: { c1: 200 } }
|
# h2 = { b: 250, c: { c1: 200 } }
|
||||||
# h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val }
|
# h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val }
|
||||||
# # => { a: 100, b: 450, c: { c1: 300 } }
|
# # => { a: 100, b: 450, c: { c1: 300 } }
|
||||||
def deep_merge(other_hash, &block)
|
def deep_merge(other_hash, &block) = dup.deep_merge!(other_hash, &block)
|
||||||
dup.deep_merge!(other_hash, &block)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Same as +deep_merge+, but modifies +self+.
|
# Same as +deep_merge+, but modifies +self+.
|
||||||
def deep_merge!(other_hash, &block)
|
def deep_merge!(other_hash, &block)
|
||||||
|
|||||||
@ -10,18 +10,15 @@ class Hash
|
|||||||
#
|
#
|
||||||
# hash.deep_transform_values{ |value| value.to_s.upcase }
|
# hash.deep_transform_values{ |value| value.to_s.upcase }
|
||||||
# # => {person: {name: "ROB", age: "28"}}
|
# # => {person: {name: "ROB", age: "28"}}
|
||||||
def deep_transform_values(&block)
|
def deep_transform_values(&block) = _deep_transform_values_in_object(self, &block)
|
||||||
_deep_transform_values_in_object(self, &block)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Destructively converts all values by using the block operation.
|
# Destructively converts all values by using the block operation.
|
||||||
# This includes the values from the root hash and from all
|
# This includes the values from the root hash and from all
|
||||||
# nested hashes and arrays.
|
# nested hashes and arrays.
|
||||||
def deep_transform_values!(&block)
|
def deep_transform_values!(&block) = _deep_transform_values_in_object!(self, &block)
|
||||||
_deep_transform_values_in_object!(self, &block)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Support methods for deep transforming nested hashes and arrays.
|
# Support methods for deep transforming nested hashes and arrays.
|
||||||
def _deep_transform_values_in_object(object, &block)
|
def _deep_transform_values_in_object(object, &block)
|
||||||
case object
|
case object
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user