Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Net::HTTPHeader#to_hash

() -> ::Hash[::String, ::Array[::String]]
to_hash

Returns a hash of the key/value pairs:

Example
req = Net::HTTP::Get.new(uri)
req.to_hash
# =>
{"accept-encoding"=>["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"],
 "accept"=>["*/*"],
 "user-agent"=>["Ruby"],
 "host"=>["jsonplaceholder.typicode.com"]}
See also #sub_type #type_params #set_range also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0