Skip to content

Commit

Permalink
Add Rack::Utils::HeaderHash#replace
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information
kamal authored and josh committed Jun 15, 2009
1 parent 5ca8f82 commit e0322ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/rack/utils.rb
Expand Up @@ -259,6 +259,12 @@ def merge(other)
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.
Expand Down
7 changes: 7 additions & 0 deletions test/spec_rack_utils.rb
Expand Up @@ -228,6 +228,13 @@
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
Expand Down

2 comments on commit e0322ed

@rtomayko
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one!

@kriskhaira
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Josh! It's a small world indeed. Wonders of FOSS development. :)

Please sign in to comment.