
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
= hash-deep-merge
== Introduction This little gem add a method to the Hash class, allowing to merge hashes containing other hashes. (This is known as "deep merge" or "recursive merge".)
You (may) already know the standard hash merge : h1 = { 'a' => 1, 'b' => 2, 'c' => 3} h2 = { 'b' => 33, 'd' => 42 } h1.merge(h2) -> { 'a' => 1, 'b' => 33, 'c' => 3, 'd' => 42 }
But now, what if the hash contains other hashes ? h1 = { :option1 => true, :option2 => false, :option_group1 => { :sub_option1 => 23, :sub_option2 => "hey !" } } h2 = { :option2 => true, :option3 => 27, :option_group1 => { :sub_option1 => 18 } } traditional merge doesn't handle that... Here come deep_merge ! h1.deep_merge(h2) -> { :option1 => true, :option2 => true, :option_group1 => { :sub_option1 => 18, :sub_option2 => "hey !" }, :option3 => 27 }
Of course, a deep_merge! (note the !) is available, like merge!
This should be included in Ruby, but there are some discussions about extra features that prevent it from going forward, cf. http://www.misuse.org/science/2008/05/19/deep_merge-ruby-recursive-merging-for-hashes/
The version I give you is the simplest one, doing what you need 99% of the time.
There are plenty of code snippets for deep merge :
But they were not packaged it into a gem. It's done now for your convenience (and mine).
NOTE : I since found a gem containing a more powerful deep merge, able to not only merge hashes but arrays and strings as well with many options. You may want to look at it : https://github.com/peritor/deep_merge
== Installation
If you use bundler, just throw that in your gemfile : gem 'hash-deep-merge'
You may also install the gem manually : gem install hash-deep-merge
Isn't it so easy ?
== Contributing to hash-deep-merge
== Copyright
Copyright (c) 2011 Offirmo. See LICENSE.txt for further details.
FAQs
Unknown package
We found that hash-deep-merge demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.