Ik_guy

Geekskillz_logo1


"Everything that boots is beautiful."


Jan 16
2008

A Class Inspection Trick for Ruby

Tags: Programming   Ruby on Rails


I was struggling with SOAP for the first time today. No, today is not the first day I bathe! SOAP is some crazy XML communication protocol that seems like overkill to me.

Anyway, I was using Ruby to send and receive the request, and I was getting a baffling SOAP::Mapping::Object object, and I had no idea how to use it. It's a class with dynamically generated methods, and none of the ones I was expecting to see were there.

Blogosphere to the rescue! Marty Haught's Weblog gave a simple trick that saved the day and helped me narrow down my problem to let me see the solution within minutes.

To inspect the resulting object, I was looking at the output of this:
@results.public_methods.sort.join(' ')

Which gives a huge list of methods.

Thanks to Marty, I did this instead:
(@results.public_methods - Object.public_methods).sort.join(' ')

Subtracting Object.public_methods removes all the methods that all Ruby objects get, showing me only the methods that are different. I got this list:
[] []= __add_xmlele_value __xmlattr __xmlele out out=

Sure enough, the "out" method stood out, so I investigated it. A few minutes later, I had navigated through the class and found what I needed. Sweet!

I post this here so that others might discover this simple trick and solve whatever problem is keeping them up late at night.



StumbleUpon This! Bookmark This Article Digg This Story

Be the first to post a comment:



Post a comment:

Name:
E-mail: (will not be sold or published)
Website: (Optional)

Your comment:

Are you human?
Please enter the
text in the picture:


About Me

ThinkGeek

Feed-icon Technorati


Loot For Geeks:
4inkjets Great Prices and Best Quality!
Man's Wig! All size heads! Handsome! Sideburns! Modacrylic Fiber!
Protection
!
Make money online selling grit! Famous men sell grit!