From: Robert Klemme Date: 2004-09-29T23:40:07+09:00 Subject: Re: ruby-dev summary 24298-24353 "SASADA Koichi" schrieb im Newsbeitrag news:20040929223720.2b31e9be%ko1@atdot.net... > Hi all, > > This is ruby-dev summary 24298-24353. > > > [ruby-dev:24302] Invoke Proc object with any method name > > Nowake proposed that a Proc object should be invoked with > any method name like that: > > m = Proc.new( :to_s ) { 'test1' } > p m.to_s # => 'test1' > > This scheme is enabled with following code: > > class MethodProc < Proc > def initialize( *method_name, &procedure ) > super( &procedure ) > m = Module.new > method_name.each do | i | > m.__send__( :define_method, i, &procedure ) > end > self.extend( m ) > end > end > > He made a point that it is helphul that a Proc object can > be handled as polymorphic. > > Matz amazed about this idea. This issue is still open. Just out of curiosity (and because I can't read Japanese) is there any advantage of using a Module over using the singleton class? As far as I can see "self.extend(m)" creates the singleton class anyway. Thinking a bit about this there could be numerous alternative approaches, some of which might be more efficient. My suggestion would be this: module Kernel private def MethodProc(*method_names, &b) raise ArgumentError, "No block given" unless b class <