diff options
author | Kamal Fariz Mahyuddin <kamal.fariz@gmail.com> | 2009-06-15 14:17:41 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-06-15 14:17:41 -0500 |
commit | e0322ed04b419e88a4790f63eb402cdce0f6a528 (patch) | |
tree | 4e37dce7fa56cb92d7c2a4992ab8cfe2bf12a362 | |
parent | 5ca8f82fb59f0bf0e8fd438e8e91c5acf3d98e44 (diff) | |
download | rack-e0322ed04b419e88a4790f63eb402cdce0f6a528.tar.gz |
Add Rack::Utils::HeaderHash#replace
Signed-off-by: Joshua Peek <josh@joshpeek.com>
-rw-r--r-- | lib/rack/utils.rb | 6 | ||||
-rw-r--r-- | test/spec_rack_utils.rb | 7 |
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb index 228488c1..0899c106 100644 --- a/lib/rack/utils.rb +++ b/lib/rack/utils.rb @@ -259,6 +259,12 @@ module Rack hash = dup hash.merge! other end + + def replace(other) + clear + other.each { |k, v| self[k] = v } + self + end end # Every standard HTTP code mapped to the appropriate message. diff --git a/test/spec_rack_utils.rb b/test/spec_rack_utils.rb index 077ccc50..36b4e7b4 100644 --- a/test/spec_rack_utils.rb +++ b/test/spec_rack_utils.rb @@ -228,6 +228,13 @@ context "Rack::Utils::HeaderHash" do h = Rack::Utils::HeaderHash.new("foo" => ["bar", "baz"]) h.to_hash.should.equal({ "foo" => "bar\nbaz" }) end + + specify "should replace hashes correctly" do + h = Rack::Utils::HeaderHash.new("Foo-Bar" => "baz") + j = {"foo" => "bar"} + h.replace(j) + h["foo"].should.equal "bar" + end end context "Rack::Utils::Context" do |