Skip to content

Commit d2d51d6

Browse files
committed
Improved documentation for Protocol::HTTP::Response.
1 parent 8f13d27 commit d2d51d6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/protocol/http/response.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ def self.for_exception(exception)
151151
Response[500, Headers["content-type" => "text/plain"], ["#{exception.class}: #{exception.message}"]]
152152
end
153153

154+
# Convert the response to a hash suitable for serialization.
155+
#
156+
# @returns [Hash] The response as a hash.
154157
def as_json(...)
155158
{
156159
version: @version,
@@ -161,14 +164,23 @@ def as_json(...)
161164
}
162165
end
163166

167+
# Convert the response to JSON.
168+
#
169+
# @returns [String] The response as JSON.
164170
def to_json(...)
165171
as_json.to_json(...)
166172
end
167173

174+
# Summarise the response as a string.
175+
#
176+
# @returns [String] The response as a string.
168177
def to_s
169178
"#{@status} #{@version}"
170179
end
171180

181+
# Implicit conversion to an array.
182+
#
183+
# @returns [Array] The response as an array, e.g. `[status, headers, body]`.
172184
def to_ary
173185
return @status, @headers, @body
174186
end

0 commit comments

Comments
 (0)