Created
December 15, 2014 06:01
-
-
Save notahat/c84e1784893d31f4e594 to your computer and use it in GitHub Desktop.
Private classes in Ruby
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 Container | |
class PublicThing | |
def hello | |
PrivateThing.new.hello | |
end | |
end | |
class PrivateThing | |
def hello | |
"Hello, world!" | |
end | |
end | |
private_constant :PrivateThing | |
end | |
Container::PublicThing.new.hello # => "Hello, world!" | |
Container::PrivateThing.new.hello # => NameError! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment