Class: Rack::Utils::HeaderHash Private
- Inherits:
-
Hash
- Object
- Hash
- Rack::Utils::HeaderHash
- Defined in:
- lib/rack/utils.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A case-insensitive Hash that preserves the original case of a header when set.
Class Method Summary collapse
-
.[](headers) ⇒ Object
private
:nodoc:.
Instance Method Summary collapse
- #[](k) ⇒ Object private
- #[]=(k, v) ⇒ Object private
-
#clear ⇒ Object
private
on clear, we need to clear @names hash.
- #delete(k) ⇒ Object private
- #each ⇒ Object private
- #include?(k) ⇒ Boolean (also: #has_key?, #member?, #key?) private
-
#initialize(hash = {}) ⇒ HeaderHash
constructor
private
A new instance of HeaderHash.
-
#initialize_copy(other) ⇒ Object
private
on dup/clone, we need to duplicate @names hash.
- #merge(other) ⇒ Object private
- #merge!(other) ⇒ Object private
- #replace(other) ⇒ Object private
- #to_hash ⇒ Object private
Constructor Details
#initialize(hash = {}) ⇒ HeaderHash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of HeaderHash.
444 445 446 447 448 |
# File 'lib/rack/utils.rb', line 444 def initialize(hash = {}) super() @names = {} hash.each { |k, v| self[k] = v } end |
Class Method Details
.[](headers) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
:nodoc:
436 437 438 439 440 441 442 |
# File 'lib/rack/utils.rb', line 436 def self.[](headers) if headers.is_a?(HeaderHash) && !headers.frozen? return headers else return self.new(headers) end end |
Instance Method Details
#[](k) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
474 475 476 |
# File 'lib/rack/utils.rb', line 474 def [](k) super(k) || super(@names[k.downcase]) end |
#[]=(k, v) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
478 479 480 481 482 483 |
# File 'lib/rack/utils.rb', line 478 def []=(k, v) canonical = k.downcase.freeze delete k if @names[canonical] && @names[canonical] != k # .delete is expensive, don't invoke it unless necessary @names[canonical] = k super k, v end |
#clear ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
on clear, we need to clear @names hash
457 458 459 460 |
# File 'lib/rack/utils.rb', line 457 def clear super @names.clear end |
#delete(k) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
485 486 487 488 489 |
# File 'lib/rack/utils.rb', line 485 def delete(k) canonical = k.downcase result = super @names.delete(canonical) result end |
#each ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
462 463 464 465 466 |
# File 'lib/rack/utils.rb', line 462 def each super do |k, v| yield(k, v.respond_to?(:to_ary) ? v.to_ary.join("\n") : v) end end |
#include?(k) ⇒ Boolean Also known as: has_key?, member?, key?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
491 492 493 |
# File 'lib/rack/utils.rb', line 491 def include?(k) super || @names.include?(k.downcase) end |
#initialize_copy(other) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
on dup/clone, we need to duplicate @names hash
451 452 453 454 |
# File 'lib/rack/utils.rb', line 451 def initialize_copy(other) super @names = other.names.dup end |
#merge(other) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
504 505 506 507 |
# File 'lib/rack/utils.rb', line 504 def merge(other) hash = dup hash.merge! other end |
#merge!(other) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
499 500 501 502 |
# File 'lib/rack/utils.rb', line 499 def merge!(other) other.each { |k, v| self[k] = v } self end |
#replace(other) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
509 510 511 512 513 |
# File 'lib/rack/utils.rb', line 509 def replace(other) clear other.each { |k, v| self[k] = v } self end |
#to_hash ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
468 469 470 471 472 |
# File 'lib/rack/utils.rb', line 468 def to_hash hash = {} each { |k, v| hash[k] = v } hash end |