Skip to content

Instantly share code, notes, and snippets.

@zilkey
Created October 22, 2013 22:40
Show Gist options
  • Save zilkey/7109439 to your computer and use it in GitHub Desktop.
Save zilkey/7109439 to your computer and use it in GitHub Desktop.
Ruby's private_constant example
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