Use built-in #transform_values when available.
The methods Hash#transform_values and Hash#transform_values! have been implemented in Ruby and they'll be available as part of the standard library. Here's the link to the discussion in Ruby's issue tracker: https://bugs.ruby-lang.org/issues/12512 These methods are implemented in C so they're expected to perform better.
This commit is contained in:
parent
159b774887
commit
e84ed4fd17
@ -16,7 +16,7 @@ def transform_values
|
||||
result[key] = yield(value)
|
||||
end
|
||||
result
|
||||
end
|
||||
end unless method_defined? :transform_values
|
||||
|
||||
# Destructively converts all values using the +block+ operations.
|
||||
# Same as +transform_values+ but modifies +self+.
|
||||
@ -25,5 +25,5 @@ def transform_values!
|
||||
each do |key, value|
|
||||
self[key] = yield(value)
|
||||
end
|
||||
end
|
||||
end unless method_defined? :transform_values!
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user