From: Paul Brannan Date: 2008-03-18T00:00:41+09:00 Subject: how to create a block with a block parameter in C? This works in Ruby (1.9): irb(main):002:0> class Foo; define_method(:foo) { |x, &b| p x, b }; end => # irb(main):004:0> Foo.new.foo(42) { 8 } 42 but I don't see how to duplicate this behavior in C: cout@bean:~/tmp/tmp$ cat foo.c #include "ruby.h" VALUE foo(VALUE yieldarg, VALUE procarg) { rb_p(yieldarg); rb_p(procarg); rb_p(rb_block_proc()); return Qnil; } VALUE dm(VALUE id) { VALUE args[] = { id }; rb_funcall2(rb_cObject, rb_intern("define_method"), 1, args); } void Init_foo() { VALUE val = INT2NUM(42); rb_iterate(dm, ID2SYM(rb_intern("foo")), foo, val); } cout@bean:~/tmp/tmp$ cat test.rb require 'foo' foo { puts "HERE" } cout@bean:~/tmp/tmp$ ruby1.9 test.rb nil 42 test.rb:3:in `
': tried to create Proc object without a block (ArgumentError) Is what I want possible? Paul