Skip to content

Commit

Permalink
Merge pull request #83 from dry-rb/accept-block-with-merge
Browse files Browse the repository at this point in the history
[changelog]

added: "Accept block given to `#merge` (via #83) (@timriley)"
  • Loading branch information
solnic authored Jul 8, 2022
2 parents 4805587 + 299e25b commit 1b99998
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/dry/container/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,16 @@ def [](key)
# @return [Dry::Container::Mixin] self
#
# @api public
def merge(other, namespace: nil)
def merge(other, namespace: nil, &block)
if namespace
_container.merge!(
other._container.each_with_object(::Concurrent::Hash.new) do |a, h|
h[PREFIX_NAMESPACE.call(namespace, a.first, config)] = a.last
end
other._container.each_with_object(::Concurrent::Hash.new) { |(key, item), hsh|
hsh[PREFIX_NAMESPACE.call(namespace, key, config)] = item
},
&block
)
else
_container.merge!(other._container)
_container.merge!(other._container, &block)
end

self
Expand Down

0 comments on commit 1b99998

Please sign in to comment.