public Method

Object.respond_to?(...)

obj.respond_to?(symbol, include_private=false)  true or false

Returns true> if obj responds to the given method. Private methods are included in the search only if the optional second parameter evaluates to true.

Source Code

/*
*  call-seq:
*     obj.respond_to?(symbol, include_private=false) => true or false
*  
*  Returns +true+> if _obj_ responds to the given
*  method. Private methods are included in the search only if the
*  optional second parameter evaluates to +true+.
*/

static VALUE
obj_respond_to(argc, argv, obj)
   int argc;
   VALUE *argv;
   VALUE obj;
{
   VALUE mid, priv;
   ID id;

   rb_scan_args(argc, argv, "11", &mid, &priv);
   id = rb_to_id(mid);
   if (rb_method_boundp(CLASS_OF(obj), id, !RTEST(priv))) {
       return Qtrue;
   }
   return Qfalse;
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.