Skip to content

Commit

Permalink
Merge pull request #281 from mgold/reverse-merge
Browse files Browse the repository at this point in the history
Add and test Hashie::Mash#reverse_merge
  • Loading branch information
dblock committed Feb 26, 2015
2 parents afd7a2d + 62281bc commit 693de89
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Expand Up @@ -12,7 +12,7 @@ Metrics/AbcSize:
# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 170
Max: 172

# Offense count: 8
Metrics/CyclomaticComplexity:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions lib/hashie/mash.rb
Expand Up @@ -255,6 +255,11 @@ def extractable_options?
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)
Expand Down
13 changes: 13 additions & 0 deletions spec/hashie/mash_spec.rb
Expand Up @@ -651,4 +651,17 @@ class SubMash < Hashie::Mash
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

0 comments on commit 693de89

Please sign in to comment.