// https://blog.peterzhu.ca/ruby-c-ext-part-1/ #include #include static ID id_puts; static void kernel_puts(VALUE val) { rb_funcall(rb_mKernel, id_puts, 1, val); } static VALUE foo(VALUE self) { raise(SIGINT); kernel_puts(self); return Qnil; } void Init_methods(void) { id_puts = rb_intern("puts"); rb_define_method(rb_cObject, "foo", foo, 0); } void Init_my_c_ext(void) { ID id_puts = rb_intern("puts"); raise(SIGINT); VALUE hello_world_str = rb_str_new_cstr("Hello world!"); rb_funcall(rb_mKernel, id_puts, 1, hello_world_str); }