From: "Berger, Daniel" Date: 2005-06-01T01:00:21+09:00 Subject: Re: Passing a block to rb_funcall > -----Original Message----- > From: nobu.nokada@softhome.net [mailto:nobu.nokada@softhome.net] > Sent: Tuesday, May 31, 2005 9:58 AM > To: ruby-talk ML > Subject: Re: Passing a block to rb_funcall > > > Hi, > > At Wed, 1 Jun 2005 00:35:22 +0900, > Daniel Berger wrote in [ruby-talk:144097]: > > I've seen some mention of rb_iterate, but I wasn't sure how > to apply > > it here. > > static VALUE > call_foreach(VALUE args) > { > return rb_funcall2(rb_cIO, rb_intern("foreach"), 2, > (VALUE *)args); } > > static VALUE > yield_block(VALUE val, VALUE block) > { > return rb_funcall2(block, rb_intern("call"), 1, &val); > } > > static VALUE > my_method(int argc, VALUE* argv, VALUE self) > { > VALUE args[2], block; > > rb_scan_args(argc, argv, "01&", &args[1], &block); > args[0] = self; > > return rb_iterate(call_foreach, (VALUE)args, yield_block, > block); } > > -- > Nobu Nakada Ah, I didn't realize it had to be broken up that way. Thanks! Dan