public Method

Module.private_method_defined?(p1)

mod.private_method_defined?(symbol)     true or false

Returns true if the named private method is defined by _ mod_ (or its included modules and, if mod is a class, its ancestors).

module A
  def method1()  end
end
class B
  private
  def method2()  end
end
class C < B
  include A
  def method3()  end
end

A.method_defined? :method1            #=> true
C.private_method_defined? "method1"   #=> false
C.private_method_defined? "method2"   #=> true
C.method_defined? "method2"           #=> false

Source Code

/*
*  call-seq:
*     mod.private_method_defined?(symbol)    => true or false
*  
*  Returns +true+ if the named private method is defined by
*  _ mod_ (or its included modules and, if _mod_ is a class,
*  its ancestors).
*     
*     module A
*       def method1()  end
*     end
*     class B
*       private
*       def method2()  end
*     end
*     class C < B
*       include A
*       def method3()  end
*     end
*     
*     A.method_defined? :method1            #=> true
*     C.private_method_defined? "method1"   #=> false
*     C.private_method_defined? "method2"   #=> true
*     C.method_defined? "method2"           #=> false
*/

static VALUE
rb_mod_private_method_defined(mod, mid)
   VALUE mod, mid;
{
   ID id = rb_to_id(mid);
   int noex;

   if (rb_get_method_body(&mod, &id, &noex)) {
       if (VISI_CHECK(noex, NOEX_PRIVATE))
           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.