Skip to content

Commit 8998860

Browse files
Add Headers#to_a method
- Adds Headers#to_a method that returns the fields array - Provides compatibility with standard Ruby array conversion pattern - Includes comprehensive tests for the new method
1 parent be65261 commit 8998860

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/protocol/http/headers.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ def flatten
108108
# @attribute [Array] An array of `[key, value]` pairs.
109109
attr :fields
110110

111+
# @returns [Array] The fields of the headers.
112+
def to_a
113+
@fields
114+
end
115+
111116
# @returns [Boolean] Whether there are any trailers.
112117
def trailer?
113118
@tail != nil

test/protocol/http/headers.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,20 @@
148148
end
149149
end
150150

151+
with "#to_a" do
152+
it "should return the fields array" do
153+
expect(headers.to_a).to be == fields
154+
end
155+
156+
it "should return the same object as fields" do
157+
expect(headers.to_a).to be_equal(headers.fields)
158+
end
159+
160+
it "should return an array" do
161+
expect(headers.to_a).to be_a(Array)
162+
end
163+
end
164+
151165
with "#to_h" do
152166
it "should generate array values for duplicate keys" do
153167
expect(headers.to_h["set-cookie"]).to be == ["hello=world", "foo=bar"]

0 commit comments

Comments
 (0)