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")

···

-----Original Message-----
From: Trans [mailto:transfire@gmail.com]
Sent: Thursday, 8 December 2005 2:08 PM
To: ruby-talk ML
Subject: Re: Are my metaprogramming underpants showing?

Hmm.... that does make it trickier b/c when will the chain end? The
only thing I can think of the top of my head is to use an '!'
method to
indicate it.

  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.

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.

···

On Dec 8, 2005, at 6:35, Daniel Sheppard wrote:

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?...
    }
}
Flickr = functor_factory

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

----
Matthew Smillie <M.B.Smillie@sms.ed.ac.uk>
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.