From: Daniel Berger Date: 2006-08-29T01:41:18+09:00 Subject: instance_eval, yield, C extensions Hi all, How do I write the code below within a C extension? I've seen a few threads about it (including ruby-talk: 86105) but I'm just not "getting it". # Assume Foo is a subclass of String module Kernel def my_meth instance_eval{ Foo.new(yield) } end end With that I can do my_meth{ "some_string" } and get back a String object. I tried this: static VALUE foo_block(VALUE self){ return rb_funcall(cFoo, rb_intern("new"), 0, rb_yield(self)); } static VALUE kernel_foo(VALUE self){ VALUE v_proc = rb_proc_new(foo_block, self); /* Also tried Qnil */ return rb_funcall(rb_cObject, rb_intern("instance_eval"), 0, v_proc); } rb_define_method(rb_mKernel, "my_meth", kernel_foo, 0); But this doesn't seem to work. When I try I do call my_meth{ "some_string" } I get `instance_eval': block not supplied (ArgumentError) What am I doing wrong here? Thanks, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments.