Skip to content

Instantly share code, notes, and snippets.

@zilkey
Created October 22, 2013 22:40
Show Gist options
  • Select an option

  • Save zilkey/7109439 to your computer and use it in GitHub Desktop.

Select an option

Save zilkey/7109439 to your computer and use it in GitHub Desktop.

Revisions

  1. zilkey created this gist Oct 22, 2013.
    21 changes: 21 additions & 0 deletions private_constant.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    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