Discussion:
Mechanize::HTTP::Agent::allowed_error_codes?
Ross Cameron
2013-09-20 05:00:01 UTC
Permalink
Mechanize version 2.7.2 shows an attribute of
Mechanize::HTTP::Agent::allowed_error_codes which is documented as R/W.

Is it public or even, implemented?

Attempting to access the attribute gives me:

undefined method `allowed_error_codes=' for
Mechanize::HTTP::Agent:Class (NoMethodError)

Would appreciate some clarity on this attribute.

Thanks in advance
Eachus Lonny
2013-09-20 05:45:53 UTC
Permalink
Ross:

If you want to find the methods of a class, one good way is to create an instance of the class, and do:

puts <your_class_instance>.methods.sort.to_yaml

and you get a nice, alphabetized list of the methods for that class, one per line.

Alternatively, you can do:

puts <your_class_instance>.public_methods.sort.to_yaml

to get just the public methods. If it's R/W, there will generally be a "method_name" and a "method_name=" in the list.

If for some strange reason you only wanted the NON-public methods, you could even do

puts (<your_class_instance>.methods - <your_class_instance>.public_methods).sort.to_yaml

You don't ALWAYS get every getter and setter method that way, because Ruby allows people to do things in funky ways if they want, and some programmers seem to like doing things in weird ways. But if they stick to "canonical Ruby" that should work.

Lonny Eachus
===========
Mechanize version 2.7.2 shows an attribute of Mechanize::HTTP::Agent::allowed_error_codes which is documented as R/W.
Is it public or even, implemented?
undefined method `allowed_error_codes=' for Mechanize::HTTP::Agent:Class (NoMethodError)
Would appreciate some clarity on this attribute.
Thanks in advance
_______________________________________________
Mechanize-users mailing list
http://rubyforge.org/mailman/listinfo/mechanize-users
Eric Hodel
2013-09-20 06:49:28 UTC
Permalink
Mechanize version 2.7.2 shows an attribute of Mechanize::HTTP::Agent::allowed_error_codes which is documented as R/W.
Is it public or even, implemented?
undefined method `allowed_error_codes=' for Mechanize::HTTP::Agent:Class (NoMethodError)
Would appreciate some clarity on this attribute.
An HTTP (and local disk access) user agent. This class is an implementation detail and is subject to change at any time.
So you cannot depend on it existing in future versions.

It is an instance method (attribute) not a class method (attribute).

You can set it like this:

m = Mechanize.new
m.agent.allowed_error_codes << 500
page = m.get 'http://example/returns_a_500'

But this is not supported use of mechanize

Instead you should:

m = Mechanize.get

page =
begin
m.get 'http://example/returnss_a_500'
rescue Mechanize::ResponseCodeError => e
e.page
end

As this is supported use of mechanize.

Loading...