Method: Module#protected
- Defined in:
- vm_method.c
#protected ⇒ nil (private) #protected(method_name) ⇒ Object (private) #protected(method_name, method_name, ...) ⇒ Array (private) #protected(array) ⇒ Array (private)
With no arguments, sets the default visibility for subsequently defined methods to protected. With arguments, sets the named methods to have protected visibility. String arguments are converted to symbols. An Array of Symbols and/or Strings is also accepted. If a single argument is passed, it is returned. If no argument is passed, nil is returned. If multiple arguments are passed, the arguments are returned as an array.
If a method has protected visibility, it is callable only where self of the context is the same as the method. (method definition or instance_eval). This behavior is different from Java’s protected method. Usually private should be used.
Note that a protected method is slow because it can’t use inline cache.
To show a private method on RDoc, use :doc: instead of this.
2493 2494 2495 2496 2497 |
# File 'vm_method.c', line 2493 static VALUE rb_mod_protected(int argc, VALUE *argv, VALUE module) { return set_visibility(argc, argv, module, METHOD_VISI_PROTECTED); } |