Skip to content

Commit

Permalink
Merge pull request #1585 from sinatra/fix-missing-commit
Browse files Browse the repository at this point in the history
Merge pull request #1572 from iguchi1124/support-ruby26-merge
  • Loading branch information
namusyaka committed Jan 1, 2020
2 parents cf1c6b1 + 63d146e commit 623a80b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## 2.0.8.1 / 2020-01-02

* Allow multiple hashes to be passed in `merge` and `merge!` for `Sinatra::IndifferentHash` [#1572](https://github.com/sinatra/sinatra/pull/1572) by Shota Iguchi

## 2.0.8 / 2020-01-01

* Lookup Tilt class for template engine without loading files [#1558](https://github.com/sinatra/sinatra/pull/1558). Fixes [#1172](https://github.com/sinatra/sinatra/issues/1172) by Jordan Owens
Expand All @@ -6,8 +10,6 @@

* Add `.yaml` support in `Sinatra::Contrib::ConfigFile` [#1564](https://github.com/sinatra/sinatra/issues/1564). Fixes [#1563](https://github.com/sinatra/sinatra/issues/1563) by Emerson Manabu Araki

* Allow multiple hashes to be passed in `merge` and `merge!` for `Sinatra::IndifferentHash` [#1572](https://github.com/sinatra/sinatra/pull/1572) by Shota Iguchi

* Remove only routing parameters from @params hash [#1569](https://github.com/sinatra/sinatra/pull/1569). Fixes [#1567](https://github.com/sinatra/sinatra/issues/1567) by Jordan Owens, Horacio

* Support `capture` and `content_for` with Hamlit [#1580](https://github.com/sinatra/sinatra/pull/1580) by Takashi Kokubun
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
2.0.8
2.0.8.1
22 changes: 13 additions & 9 deletions lib/sinatra/indifferent_hash.rb
Expand Up @@ -132,22 +132,26 @@ def values_at(*keys)
super(*keys)
end

def merge!(other_hash)
return super if other_hash.is_a?(self.class)

other_hash.each_pair do |key, value|
key = convert_key(key)
value = yield(key, self[key], value) if block_given? && key?(key)
self[key] = convert_value(value)
def merge!(*other_hashes)
other_hashes.each do |other_hash|
if other_hash.is_a?(self.class)
super(other_hash)
else
other_hash.each_pair do |key, value|
key = convert_key(key)
value = yield(key, self[key], value) if block_given? && key?(key)
self[key] = convert_value(value)
end
end
end

self
end

alias_method :update, :merge!

def merge(other_hash, &block)
dup.merge!(other_hash, &block)
def merge(*other_hashes, &block)
dup.merge!(*other_hashes, &block)
end

def replace(other_hash)
Expand Down
14 changes: 14 additions & 0 deletions test/indifferent_hash_test.rb
Expand Up @@ -205,6 +205,20 @@ def test_merge
assert_equal 2, hash2[?q]
end

def test_merge_with_multiple_argument
hash = Sinatra::IndifferentHash.new.merge({a: 1}, {b: 2}, {c: 3})
assert_equal 1, hash[?a]
assert_equal 2, hash[?b]
assert_equal 3, hash[?c]

hash2 = Sinatra::IndifferentHash[d: 4]
hash3 = {e: 5}
hash.merge!(hash2, hash3)

assert_equal 4, hash[?d]
assert_equal 5, hash[?e]
end

def test_replace
@hash.replace(?a=>1, :q=>2)
assert_equal({ ?a=>1, ?q=>2 }, @hash)
Expand Down

0 comments on commit 623a80b

Please sign in to comment.