Module: RuboCop::SortedMethodsByCall::Util
- Defined in:
- lib/rubocop/sorted_methods_by_call/extensions/util.rb
Overview
:nodoc:
Class Method Summary collapse
-
.deep_merge(h, other) ⇒ Hash
RuboCop::SortedMethodsByCall::Util.deep_merge(hash, other) -> Hash.
Class Method Details
.deep_merge(h, other) ⇒ Hash
RuboCop::SortedMethodsByCall::Util.deep_merge(hash, other) -> Hash
Merges two hashes without overwriting values that share the same key. When a key exists in both hashes, values are accumulated into an array (“buckets”). Scalars are wrapped to arrays automatically.
-
Non-destructive: returns a new Hash; does not mutate
hash. -
If
otheris not a Hash, the originalhashis returned as-is.
25 26 27 28 29 |
# File 'lib/rubocop/sorted_methods_by_call/extensions/util.rb', line 25 def self.deep_merge(h, other) return h unless other.is_a?(Hash) h.merge(other) { |_, a, b| Array(a) + Array(b) } end |