Skip to content

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_class_method

mod.private_class_method(symbol, ...) → mod
mod.private_class_method(string, ...) → mod
mod.private_class_method(array) → mod

Makes existing class methods private. Often used to hide the default constructor new.

String arguments are converted to symbols. An Array of Symbols and/or Strings are also accepted.

Example
class SimpleSingleton  # Not thread safe
  private_class_method :new
  def SimpleSingleton.create(*args, &block)
    @me = new(*args, &block) if ! @me
    @me
  end
end

Ruby version changes

  1. 3.0