Created
October 22, 2013 22:40
-
-
Save zilkey/7109439 to your computer and use it in GitHub Desktop.
Ruby's private_constant example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Foo | |
class Bar | |
end | |
private_constant :Bar | |
end | |
module Foo | |
p Bar.new # => works fine because we're scoped to Foo | |
class Baz | |
p Bar.new # => still fine, because we're still scoped to Foo | |
end | |
end | |
begin | |
Foo::Bar # => private constant Foo::Bar referenced | |
rescue Exception => e | |
puts e.message | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment