Blog An exploration of the art and
craft of software development

Object methods

Posted by Marty Haught on Sunday, August 06, 2006
Now this won't be new to most experienced Rubyists but this is something that I've learned recently that has been quite helpful. When I'm dealing with these Soap mapping objects I don't always know what I'm getting back. One of the important things I need to know is what sort of attributes may have been mapped. You typically would do this (in irb):


Which yields this:

=> ["[]=", "inspect", "send", "a=", "clone", "public_methods", "__send__", "pretty_print", "equal?", "freeze", "to_yaml_style", "__xmlele", "methods", "instance_eval", "dup", "instance_variables", "extend", "instance_of?", "__add_xmlele_value", "eql?", "to_yaml_properties", "hash", "id", "singleton_methods", "taint", "pretty_print_inspect", "lifetime", "frozen?", "instance_variable_get", "kind_of?", "to_a", "sessionId", "lifetime=", "display", "taguri", "type", "protected_methods", "sessionId=", "method", "==", "taguri=", "===", "instance_variable_set", "is_a?", "to_yaml", "respond_to?", "to_s", "authToken", "pretty_print_instance_variables", "class", "dclone", "tainted?", "=~", "private_methods", "authToken=", "__xmlattr", "__id__", "pretty_print_cycle", "nil?", "untaint", "object_id", "a", "[]"]

Useful but a bit cluttered. Instead you can do this:

auth.methods - Object.methods
=> ["[]=", "a=", "__xmlele", "__add_xmlele_value", "lifetime", "sessionId", "lifetime=", "sessionId=", "authToken", "authToken=", "__xmlattr", "a", "[]"]

Much nicer eh? It strips off all the Object class methods that are present on all objects. In this case I've learned that my new AuthResponse indeed has the sessionId, authToken attributes, which was what I was looking for.

blog comments powered by Disqus