Issue #8275 has been updated by vipulnsward (Vipul Amler).


=begin

And vice-versa for set too maybe

(({Module#public_const_set}))/
(({Module#private_const_set}))


=end
----------------------------------------
Feature #8275: Add Module#public_const_get
https://bugs.ruby-lang.org/issues/8275#change-38612

Author: rkh (Konstantin Haase)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


Right now, `const_get` will always return a constant, no matter the visibility, which is probably what we want most of the time. But if you for instance have code that does some automatic name to constant resolution, you might now want to leak private constants.

module Foo
  Bar = 42
  private_constant :Bar
end

# currently:
Foo::Bar # raises NameError
Foo.const_get("Bar") # => 42
Object.const_get("Foo::Bar") # => 42

# proposed:
Foo.public_const_get("Bar") # raises NameError
Object.public_const_get("Foo::Bar") # raises NameError


-- 
http://bugs.ruby-lang.org/