APIdock / Ruby
/
method

method_defined?

v2_5_5 - Show latest stable - Class: Module
method_defined?(p1)
public

Returns true if the named method is defined by mod (or its included modules and, if mod is a class, its ancestors). Public and protected methods are matched. String arguments are converted to symbols.

module A
 def method1() end
 def protected_method1() end
 protected  :protected_method1
end
class B
 def method2() end
 def private_method2() end
 private  :private_method2
end
class C < B
 include  A
 def method3() end
end
A.method_defined?  :method1 #=> true
C.method_defined?  "method1" #=> true
C.method_defined?  "method2" #=> true
C.method_defined?  "method3" #=> true
C.method_defined?  "protected_method1" #=> true
C.method_defined?  "method4" #=> false
C.method_defined?  "private_method2" #=> false
static VALUE
rb_mod_method_defined(VALUE mod, VALUE mid)
{
 ID id = rb_check_id(&mid);
 if (!id || !rb_method_boundp(mod, id, 1)) {
 return Qfalse;
 }
 return Qtrue;
}

AltStyle によって変換されたページ (->オリジナル) /