End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Module#private
private → self
private(symbol, ...) → self
private(string, ...) → self
private(array) → self
vm_method.c
View on GitHub ↗
static VALUE
rb_mod_private(int argc, VALUE *argv, VALUE module)
{
return set_visibility(argc, argv, module, METHOD_VISI_PRIVATE);
}
With no arguments, sets the default visibility for subsequently defined methods to private. With arguments, sets the named methods to have private visibility. String arguments are converted to symbols. An Array of Symbols and/or Strings are also accepted.
Example
module Mod def a() end def b() end private def c() end private :a end Mod.private_instance_methods #=> [:a, :c]
Note that to show a private method on RDoc, use :doc:.
Ruby version changes
-
3.0
-
Module#public,Module#protected,Module#private,Module#public_class_method,Module#private_class_method, toplevel “private” and “public” methods now accept single array argument with a list of method names. [Feature #17314]
-
See also
#prepend_features
#private_class_method
#prepended
#private_constant
also in
4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1