Method#to_proc$B$HB?CM(B

e$B<r0f$G$9!#e(B

Method#[email protected]@$H$7$F!“e(B1.9e$B$Ne(Bmethod_proc()e$B$N%=!<%9$K$O0J2<$N$h$&$Je(B
e$B%3%a%s%H$,$”$j$^$9$,!"$3$l$O<B:]$N?6$kIq$$$H$O0lCW$7$F$$$^$;$s!#e(B

/*
 * class Method
 *   def to_proc
 *     proc{|*args|
 *       self.call(*args)
 *     }
 *   end
 * end
 */

e$B0J2<$N$h$&$J%3!<%I$r<B9T$7$?$H$-!"e(B
e$B%3%a%s%H$NDL$j$N<BAu$J$i$Pe(B 1 e$B$,I=<($5$l$k$O$:$G$9$,!"e(B
e$B<B:]$K$Oe(B 0 e$B$,I=<($5$l$^$9!#e(B

def m(*args)
p args.length
end
method(:m).to_proc.call([])

[email protected]$G$9!#e(B

Tanaka A. wrote:

e$B$F$-$H$&$K$$$8$C$F$_$k$H!"$3$s$J46$8$G$7$g$&$+!#e(B

e$B!!9M$($F$_$?$i!"[email protected]$$$?$$;w$?$h$&$J46$8$N%3!<%I$K$J$j$^$7$?!#e(B

[email protected]!“e(BC e$B%l%Y%k$K$*$1$k%V%m%C%/0z?tEO$7$K$D$$$F$O$^$H$b$K8!F$e(B
e$B$5$l$F$$$J$$$N$G!”$=$3$+$i;O$a$J$$$H!"$H$$$&46$8$,$7$^$9$,!#e(B

e$B!!$&!<$s!"3N$+$K!#e(B

In article [email protected],
Masahiro S. (e$B<[email protected]/M5e(B) removed[email protected] writes:

e$B0J2<$N$h$&$J%3!<%I$r<B9T$7$?$H$-!"e(B
e$B%3%a%s%H$NDL$j$N<BAu$J$i$Pe(B 1 e$B$,I=<($5$l$k$O$:$G$9$,!"e(B
e$B<B:]$K$Oe(B 0 e$B$,I=<($5$l$^$9!#e(B

def m(*args)
p args.length
end
method(:m).to_proc.call([])

e$B$F$-$H$&$K$$$8$C$F$_$k$H!"$3$s$J46$8$G$7$g$&$+!#e(B

[email protected]!“e(BC e$B%l%Y%k$K$*$1$k%V%m%C%/0z?tEO$7$K$D$$$F$O$^$H$b$K8!F$e(B
e$B$5$l$F$$$J$$$N$G!”$=$3$+$i;O$a$J$$$H!"$H$$$&46$8$,$7$^$9$,!#e(B

Index: proc.c

— proc.c (e$B%j%S%8%g%se(B 12587)
+++ proc.c (e$B:n6H%3%T!<e(B)
@@ -1320,6 +1320,12 @@
}

static VALUE
+mlambda(VALUE method)
+{

  • return rb_funcall(Qnil, rb_intern(“lambda”), 0);
    +}

+static VALUE
bmcall(VALUE args, VALUE method)
{
volatile VALUE a;
@@ -1363,7 +1369,7 @@
* end
* end
*/

  • proc = rb_iterate((VALUE (*)(VALUE))mproc, 0, bmcall, method);
  • proc = rb_iterate((VALUE (*)(VALUE))mlambda, 0, bmcall, method);
    return proc;
    }

Index: vm.c

— vm.c (e$B%j%S%8%g%se(B 12587)
+++ vm.c (e$B:n6H%3%T!<e(B)
@@ -665,15 +665,25 @@
NODE *ifunc = (NODE *) block->iseq;
VALUE val;
VALUE arg;

  • rb_proc_t *proc = NULL;
  • if (argc == 1) {
  • arg = *argv;
  • if (block->proc) {
  •    GetProcPtr(block->proc, proc);
    
    }
  • else if (argc > 1) {
  • arg = rb_ary_new4(argc, argv);
  • if (proc && proc->is_lambda) {
  •    arg = rb_ary_new4(argc, argv);
    
    }
    else {
  • arg = rb_ary_new();
  •    if (argc == 1) {
    
  •        arg = *argv;
    
  •    }
    
  •    else if (argc > 1) {
    
  •        arg = rb_ary_new4(argc, argv);
    
  •    }
    
  •    else {
    
  •        arg = rb_ary_new();
    
  •    }
    

    }

    push_frame(th, 0, FRAME_MAGIC_IFUNC,

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs