Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/core/ruby/hash.rb
1154 views
1
#
2
# Copyright (c) 2006-2025 Wade Alcorn - [email protected]
3
# Browser Exploitation Framework (BeEF) - https://beefproject.com
4
# See the file 'doc/COPYING' for copying permission
5
#
6
class Hash
7
# Recursively deep merge two hashes together
8
# @param [Hash] hash Hash to be merged
9
# @return [Hash] Combined hash
10
# @note Duplicate keys are overwritten by the value defined
11
# in the hash calling deep_merge (not the parameter hash)
12
# @note http://snippets.dzone.com/posts/show/4706
13
def deep_merge(hash)
14
target = dup
15
hash.keys.each do |key|
16
if hash[key].is_a?(Hash) && self[key].is_a?(Hash)
17
target[key] = target[key].deep_merge hash[key]
18
next
19
end
20
target[key] = hash[key]
21
end
22
target
23
end
24
end
25
26