Skip to content

Instantly share code, notes, and snippets.

@methodmissing
Created August 22, 2009 18:14
Show Gist options
  • Select an option

  • Save methodmissing/172903 to your computer and use it in GitHub Desktop.

Select an option

Save methodmissing/172903 to your computer and use it in GitHub Desktop.
static VALUE rb_callback_initialize( int argc, VALUE *argv, VALUE cb )
{
VALUE object;
VALUE method;
ID meth;
RCallback* cbs = GetCallbackStruct(cb);
if (rb_block_given_p()) {
if (argc == 1) rb_raise(rb_eArgError, "wrong number of arguments");
cbs->object = rb_block_proc();
cbs->method = id_call;
}else {
rb_scan_args(argc, argv, "02", &object, &method);
cbs->object = object;
meth = rb_to_id(method);
if (!rb_respond_to(object,meth)) rb_raise(rb_eArgError, "object does not respond to %s", RSTRING_PTR(rb_obj_as_string(method)));
cbs->method = meth;
}
OBJ_FREEZE(cb);
return cb;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment