Skip to content

Commit

Permalink
brew vendor-gems: commit updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Jan 12, 2024
1 parent 3e1e3ae commit 331d7fb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 28 deletions.
4 changes: 1 addition & 3 deletions Library/Homebrew/extend/hash/deep_merge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ class Hash
# h2 = { b: 250, c: { c1: 200 } }
# h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val }
# # => { a: 100, b: 450, c: { c1: 300 } }
def deep_merge(other_hash, &block)
dup.deep_merge!(other_hash, &block)
end
def deep_merge(other_hash, &block) = dup.deep_merge!(other_hash, &block)

# Same as +deep_merge+, but modifies +self+.
def deep_merge!(other_hash, &block)
Expand Down
47 changes: 22 additions & 25 deletions Library/Homebrew/extend/hash/deep_transform_values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,35 @@ class Hash
#
# hash.deep_transform_values{ |value| value.to_s.upcase }
# # => {person: {name: "ROB", age: "28"}}
def deep_transform_values(&block)
_deep_transform_values_in_object(self, &block)
end
def deep_transform_values(&block) = _deep_transform_values_in_object(self, &block)

# Destructively converts all values by using the block operation.
# This includes the values from the root hash and from all
# nested hashes and arrays.
def deep_transform_values!(&block)
_deep_transform_values_in_object!(self, &block)
end
def deep_transform_values!(&block) = _deep_transform_values_in_object!(self, &block)

private
# Support methods for deep transforming nested hashes and arrays.
def _deep_transform_values_in_object(object, &block)
case object
when Hash
object.transform_values { |value| _deep_transform_values_in_object(value, &block) }
when Array
object.map { |e| _deep_transform_values_in_object(e, &block) }
else
yield(object)
end

# Support methods for deep transforming nested hashes and arrays.
def _deep_transform_values_in_object(object, &block)
case object

Check warning on line 24 in Library/Homebrew/extend/hash/deep_transform_values.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/hash/deep_transform_values.rb#L24

Added line #L24 was not covered by tests
when Hash
object.transform_values { |value| _deep_transform_values_in_object(value, &block) }
when Array
object.map { |e| _deep_transform_values_in_object(e, &block) }
else
yield(object)
end
end

def _deep_transform_values_in_object!(object, &block)
case object
when Hash
object.transform_values! { |value| _deep_transform_values_in_object!(value, &block) }
when Array
object.map! { |e| _deep_transform_values_in_object!(e, &block) }
else
yield(object)
end
def _deep_transform_values_in_object!(object, &block)
case object
when Hash
object.transform_values! { |value| _deep_transform_values_in_object!(value, &block) }
when Array
object.map! { |e| _deep_transform_values_in_object!(e, &block) }
else
yield(object)
end
end
end

0 comments on commit 331d7fb

Please sign in to comment.