On Nov 1, 2005, at 10:57 AM, Trans wrote:
> To get hold of a first class method we have to do method(:meth). Many
> of us have wanted something briefer (of course this ties into the  
> whole
> UnboundMethod/Method/Lambda/Proc/Block craziness, nontheless...) So  
> why
> not have the two on the same footing then?
>
>   lam = lambda do ; 1 ; end
>   lam #=> 1

Something tells me that it will be impossible to have an identical
syntax for all of:

1)  local variable
2)  0-argument method invocation
3)  formal parameters
4)  0-argument Proc#call invocation

It is pretty easy to package up define_method and have a very concise  
way
to define methods on demand.  This lets you associate a block with a
name (a method name) at will.  The only "gotcha" is that you are working
within the namespace of the object's methods and not the namespace of
the the method itself (as with local variables).

class A
   def fn(symbol, &block)
     (class <<self; self; end).send(:define_method, symbol, &block)
   end
   def method_missing(symbol, *args, &block)
     fn(symbol, &block)
   end

   def m1
     m2 {|n| 2*n}
     fn(:m3){|n| 3*n }

     puts m2(4)      # -> 8
     puts m3(4)      # -> 12
   end
end

A.new.m1






Gary Wright