Method: Module#protected

Defined in:
vm_method.c

#protectedself (private) #protected(symbol, ...) ⇒ self (private) #protected(string, ...) ⇒ self (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.

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.

Overloads:

  • #protectedself

    Returns:

    • (self)
  • #protected(symbol, ...) ⇒ self

    Returns:

    • (self)
  • #protected(string, ...) ⇒ self

    Returns:

    • (self)


1740
1741
1742
1743
1744
# File 'vm_method.c', line 1740

static VALUE
rb_mod_protected(int argc, VALUE *argv, VALUE module)
{
    return set_visibility(argc, argv, module, METHOD_VISI_PROTECTED);
}