From: Gavin Sinclair Date: 2003-11-28T20:08:57+09:00 Subject: Re: Controlled block variables On Friday, November 28, 2003, 7:00:20 PM, T. wrote: > Like I said, I may be overlooking something obvious here, but what i mean is > this: > class Example > def ameth > proc { |x| x + 1 } > end > end > e = Example.new > e.ameth # return equiv. to proc { |x| x + 1 } > # But... > e.ameth(2) # -> 3 > In otherwords, Ruby wouldn't assume that the arity is automatically wrong, but > rather that the method may return a proc (or method) to which the parameters > can be applied. Granted, this may mean the possibility of not so obvious > errors when it is not the case. And like I said, there may be something I'm > overlooking that makes this impossible. But that's the thought I'm having, > anyway. It further means that > e.ameth()(2) # -> 3 > actually means something --it is the "unambiguous" form of the above. >> I sympathise with the wish that methods be first class, and that you can >> pass them around, but when I red Jim Weirich's article >> (http://onestepback.org/index.cgi/Tech/Ruby/PythonAndRuby.rdoc) that door >> forever closed in my mind. > That's what I read. And I'm not really suggesting that they be first class > objects. Only that Ruby might be able to "fake it", so to speak. It's not faking anything, though. e.ameth is a callable object (it looks like a callable object, therefore it looks like it's faking method-as-a-first-class-object) only because it *is* a Proc. Method-as-a-first-class-object requires that for any value of 'e' and 'ameth', the following holds true: e.ameth is a callable object, unless it's a NoMethodError. In the case you describe, it's only the case if e.ameth returns a Proc, so it's a very special case. We can forget about methods, etc. What we're talking about comes down to this: should this syntax work? p = proc { |x| x + 1 } n = p(5) # => 6 That has been discussed on the list before. I'm not au fait with all the whys and wherefores, but the proposition has never excited me, nor has it gathered significant support. Cheers, Gavin