Skip to content

Instantly share code, notes, and snippets.

@notahat
Created December 15, 2014 06:01
Show Gist options
  • Save notahat/c84e1784893d31f4e594 to your computer and use it in GitHub Desktop.
Save notahat/c84e1784893d31f4e594 to your computer and use it in GitHub Desktop.
Private classes in Ruby
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