On Tue, 2009-09-29 at 02:13 +0900, Roger Pack wrote:
> I read somewhere that in 1.8.6 you can't do
> 
> def foo(proc)
>   bar(&proc)
> end
> 
> in C.
> 
> Is this true?

You can do this:

static VALUE
bar_i(VALUE self, VALUE proc)
{
    return rb_funcall(proc, rb_intern("call"), 0);
}

static VALUE
call_bar(VALUE self)
{
    return rb_funcall(self, rb_intern("bar"), 0);
}

static VALUE
rb_bar(VALUE self)
{
    return rb_yield(self);
}

static VALUE
rb_foo(VALUE self, VALUE proc)
{
    return rb_iterate(call_bar, self, bar_i, proc);
}

void
Init_c(void)
{
    VALUE klass = rb_define_class("C", rb_cObject);
    rb_define_method(klass, "foo", rb_foo, 1);
    rb_define_method(klass, "bar", rb_bar, 0);
}

require 'c'
C.new.foo(Proc.new { puts 'hello' })


HTH,
Andre