Ruby 4.1 リファレンスマニュアル

instance method Module#private_constant

private_constant(*name) -> selfRuby 1.9.3 から[permalink][rdoc][edit]

name で指定した定数の可視性を private に変更します。

[PARAM] name:
0 個以上の StringSymbol を指定します。
[EXCEPTION] NameError:
存在しない定数を指定した場合に発生します。
[RETURN]
self を返します。

[SEE_ALSO] Module#public_constant

module Api
  VERSION = '1.0'
  class Client; end
  SECRET = 'token'
  class Internal; end

  private_constant :SECRET
  private_constant :Internal
end

p Api::VERSION  # => "1.0"
p Api::Client   # => Api::Client
Api::SECRET     # ~> NameError: private constant Api::SECRET referenced
Api::Internal   # ~> NameError: private constant Api::Internal referenced