/*
* call-seq:
* method.dump(limit) => String
*
* Dump a Method and the object to which it is bound to a String. The
* Method's class will not be dumped, only the name of the class.
*
* Unfortunately, this means that methods for anonymous classes can be
* dumped but cannot be loaded.
*/
static VALUE method_dump(VALUE self, VALUE limit)
{
struct METHOD * method;
VALUE arr;
if(ruby_safe_level >= 4)
{
/* no access to potentially sensitive data from the sandbox */
rb_raise(rb_eSecurityError, "Insecure: can't dump method");
}
arr = rb_ary_new();
Data_Get_Struct(self, struct METHOD, method);
rb_ary_push(arr, rb_mod_name(METHOD_OCLASS(method)));
#if RUBY_VERSION_CODE >= 180
rb_ary_push(arr, rb_mod_name(METHOD_RCLASS(method)));
#else
rb_ary_push(arr, rb_mod_name(METHOD_OCLASS(method)));
#endif
if(rb_class_of(self) == rb_cUnboundMethod)
{
rb_ary_push(arr, Qnil);
}
else
{
rb_ary_push(arr, method->recv);
}
rb_ary_push(arr, ID2SYM(method->id));
rb_ary_push(arr, ID2SYM(method->oid));
rb_ary_push(arr, method_body(self));
return marshal_dump(arr, limit);
}