Re: Are my metaprogramming underpants showing?

Considering that there seems to be at least one mandatory argument
(api_key), you could do:

require ‘calibre/functor’

functor_factory = lambda { |*symbols|
Functor.new { |op, *args|
new_sym = symbols+[op]
if args.empty?
functor_factory[*new_sym]
else
puts “call:
http://flickr.com/services/rest/?method=‘#{new_sym}’
puts “with parameters:”
p args
end
}
}
Flickr = functor_factory[]

Flickr.test.echo.momma(“api_key” => “something long”, “foo” => “bar”)

Flickr.test.echo!

Then you can just return the same Functor-like object collecting the
parts along the way until the ‘!’ is hit.

T.

#####################################################################################
This email has been scanned by MailMarshal, an email content filter.
#####################################################################################

Daniel…

WAY COOL!

T.

On Dec 8, 2005, at 6:35, Daniel S. wrote:

}
Flickr = functor_factory[]

Flickr.test.echo.momma(“api_key” => “something long”, “foo” => “bar”)

Maybe this makes me sound thick, but then again, enlightenment is the
reason I’m posting.

Given that the code below is functionally equivalent, what’s
beneficial about using a lambda expression? It strikes me as a
requirement imposed by using the Functor class more than anything.

class Flickr
def initialize (method = [‘flickr’])
@method = method
end

def method_missing(method_id, *params)
new_method = @method + [method_id]
if params.empty?
self.class.new(new_method)
else
puts “call: http://flickr.com/services/rest/method=#
{new_method.join(‘.’)}”
p params
end
end
end

flickr = Flickr.new
flickr.test.echo.momma(“api_key” => “something long”, “foo” => “bar”)

thanks again for the input,
matthew smillie.


Matthew S. [email protected]
Institute for Communicating and Collaborative Systems
University of Edinburgh

Given that the code below is functionally equivalent, what’s
beneficial about using a lambda expression?

I don’t think there is neccessarily. Functor’s just the completely
generic form of this. Making a specifec Functor-like class as you have
here with this Flickr class is ceratinly the way to go.

T.