Documentation says Net::HTTPResponse mixes in HTTPHeader, but I can't access its methods

I'm using Ruby 1.9.3-p448 and looking at the Standard Library API
reference which comes as CHM file and I see the following:

Class Net::HTTPResponse ... It mixes in the HTTPHeader module, which
provides access to response header values both via hash-like methods and
via individual readers. ...

Then I'm starting irb session and doing this:

require 'net/http'
h=Net::HTTP.start 'example.com'
r=h.get '/'
p r.get_fields 'set-cookie'

The last line fails with an error: "NoMethodError: undefined method
`get_field' for..."

Why is that? The r is an object of the class Net::HTTPOK, which has
the following ancestors: [Net::HTTPOK, Net::HTTPSuccess,
Net::HTTPResponse, Net::HTTPHeader, Object, Kernel, BasicObject]

Net::HTTPHeader.methods.grep /field/ yields nothing. Does it turn out
that the documentation is incorrect? I'm puzzled.

Thanks for any comments on this.

···

--
Posted via http://www.ruby-forum.com/.

Quoting Andrey Panin (lists@ruby-forum.com):

Net::HTTPHeader.methods.grep /field/ yields nothing. Does it turn out
that the documentation is incorrect? I'm puzzled.

Wth your statement you search for *class* methods. The get_fields
method is an *instance* method:

require 'net/http'
h=Net::HTTP.start('example.com')
r=h.get('/')
p r.methods.grep(/field/)

-> [:add_field, :get_fields]

If you want to access all fields, you can obtain a hash this way:

all_fields=r.to_hash

From example.com I get these fields:

{"accept-ranges"=>["bytes"],
"cache-control"=>["max-age=604800"],
"content-type"=>["text/html"],
"date"=>["Wed, 04 Sep 2013 05:22:00 GMT"],
"etag"=>["\"3012602696\""],
"expires"=>["Wed, 11 Sep 2013 05:22:00 GMT"],
"last-modified"=>["Fri, 09 Aug 2013 23:54:35 GMT"],
"server"=>["ECS (mia/1791)"],
"x-cache"=>["HIT"],
"x-ec-custom-error"=>["1"],
"content-length"=>["1270"]}

Carlo

···

Subject: Documentation says Net::HTTPResponse mixes in HTTPHeader, but I can't access its methods
  Date: mer 04 set 13 06:59:16 +0200

--
  * Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
  * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)