From: Paolo Nusco Perrotta Date: 2007-09-09T20:55:07+09:00 Subject: Re: Better way to do this? Currently using two method_missing calls... On Aug 4, 1:49 am, Dan wrote: > For example, if my ruby class is named API, I want to be able to call > API.images.find_by_name and have my class pass along "images" and > "find_by_name" to the remove service. I've got this working using two > method_missing calls (one as a class method and one as an instance > method), but it looks sloppy and I was wondering if there was a better > way to do this. Any ideas? The flickr library (available via RubyGems) walks around the problem by turning a Flickr API call such as: flickr.tags.getListUser into a Ruby call like: flickr.tags_getListUser so that it can forward the method to Flickr through a single method_missing. It also provides a more granular object model around the call, so there is still some duplication left: class Flickr class User def tags # @client is a Flickr object @client.tags_getListUser('user_id'=>@id)['who']['tags'] ['tag'].collect { |tag| tag } end ... You might or might not like this, but it looks like a decent trade-off to me. It's simple, and you can still make calls to the back-end that are not directly supported by your Ruby code. --- Paolo Perrotta - Bologna, Italy Now writing: "Metaprogramming Ruby"