# Re: Are my metaprogramming underpants showing?

**URL:** <https://www.ruby-forum.com/t/re-are-my-metaprogramming-underpants-showing/95966>\
**Category:** Ruby\
**Created:** [December 8, 2005, 7:36am UTC](https://www.ruby-forum.com/t/re-are-my-metaprogramming-underpants-showing/95966 "2005-12-08T07:36:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3ab097/32.png) [@daniels](https://www.ruby-forum.com/u/daniels)\
**Post date:** [December 8, 2005, 7:36am UTC](https://www.ruby-forum.com/t/re-are-my-metaprogramming-underpants-showing/95966/1 "2005-12-08T07:36:26Z")

</div>

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}’](http://flickr.com/services/rest/?method='#%7Bnew_sym%7D')”  
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.  
#####################################################################################

---

<div class="post-metadata">

**Author:** ![daniels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3ab097/32.png) [@daniels](https://www.ruby-forum.com/u/daniels)\
**Post date:** [December 8, 2005, 8:13am UTC](https://www.ruby-forum.com/t/re-are-my-metaprogramming-underpants-showing/95966/2 "2005-12-08T08:13:09Z")

</div>

Daniel…

WAY COOL!

T.

---

<div class="post-metadata">

**Author:** ![daniels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3ab097/32.png) [@daniels](https://www.ruby-forum.com/u/daniels)\
**Post date:** [December 8, 2005, 5:15pm UTC](https://www.ruby-forum.com/t/re-are-my-metaprogramming-underpants-showing/95966/3 "2005-12-08T17:15:11Z")

</div>

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=#](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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Institute for Communicating and Collaborative Systems  
University of Edinburgh

---

<div class="post-metadata">

**Author:** ![daniels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3ab097/32.png) [@daniels](https://www.ruby-forum.com/u/daniels)\
**Post date:** [December 8, 2005, 6:29pm UTC](https://www.ruby-forum.com/t/re-are-my-metaprogramming-underpants-showing/95966/4 "2005-12-08T18:29:53Z")

</div>

> 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.
