summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Doubrovkine (dB.) @dblockdotorg <dblock@dblock.org>2015-02-25 19:15:33 -0500
committerDaniel Doubrovkine (dB.) @dblockdotorg <dblock@dblock.org>2015-02-25 19:15:33 -0500
commit693de89e77eb0a11c093e5b9f11f2fabe8d27e81 (patch)
treee92a8370430514151ff1a151e58c36fc03c0abc4
parentafd7a2d6b4a3668825a9b524768b23d8d7947b13 (diff)
parent62281bca63d9a532969d1babfcf7ccdbf9a000e9 (diff)
downloadhashie-693de89e77eb0a11c093e5b9f11f2fabe8d27e81.tar.gz
Merge pull request #281 from mgold/reverse-merge
Add and test Hashie::Mash#reverse_merge
-rw-r--r--.rubocop_todo.yml2
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/hashie/mash.rb5
-rw-r--r--spec/hashie/mash_spec.rb13
4 files changed, 20 insertions, 1 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 630134c..3ee5c95 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -12,7 +12,7 @@ Metrics/AbcSize:
# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
- Max: 170
+ Max: 172
# Offense count: 8
Metrics/CyclomaticComplexity:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7da4ca0..f6c3e51 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
* [#269](https://github.com/intridea/hashie/pull/272): Added Hashie::Extensions::DeepLocate - [@msievers](https://github.com/msievers).
* [#270](https://github.com/intridea/hashie/pull/277): Fixed ArgumentError raised when using IndifferentAccess and HashWithIndifferentAccess - [@gardenofwine](https://github.com/gardenofwine).
+* [#281](https://github.com/intridea/hashie/pull/281): Added #reverse_merge to Mash to override ActiveSupport's version - [@mgold](https://github.com/mgold).
* Your contribution here
## 3.4.0 (02/02/2014)
diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb
index e4927e8..1428816 100644
--- a/lib/hashie/mash.rb
+++ b/lib/hashie/mash.rb
@@ -255,6 +255,11 @@ module Hashie
true
end
+ # another ActiveSupport method, see issue #270
+ def reverse_merge(other_hash)
+ Hashie::Mash.new(other_hash).merge(self)
+ end
+
protected
def method_suffix(method_name)
diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb
index 640c3af..ce78052 100644
--- a/spec/hashie/mash_spec.rb
+++ b/spec/hashie/mash_spec.rb
@@ -651,4 +651,17 @@ describe Hashie::Mash do
expect(args).to eq [101, 'bar']
end
end
+
+ describe '#reverse_merge' do
+ subject { described_class.new(a: 1, b: 2) }
+
+ it 'unifies strings and symbols' do
+ expect(subject.reverse_merge(a: 2).length).to eq 2
+ expect(subject.reverse_merge('a' => 2).length).to eq 2
+ end
+
+ it 'does not overwrite values' do
+ expect(subject.reverse_merge(a: 5).a).to eq subject.a
+ end
+ end
end