1module ConstantVisibility 2 module ModuleContainer 3 module PrivateModule 4 end 5 private_constant :PrivateModule 6 7 class PrivateClass 8 end 9 private_constant :PrivateClass 10 end 11 12 class ClassContainer 13 module PrivateModule 14 end 15 private_constant :PrivateModule 16 17 class PrivateClass 18 end 19 private_constant :PrivateClass 20 end 21 22 module PrivConstModule 23 PRIVATE_CONSTANT_MODULE = true 24 private_constant :PRIVATE_CONSTANT_MODULE 25 26 def self.private_constant_from_self 27 PRIVATE_CONSTANT_MODULE 28 end 29 30 def self.defined_from_self 31 defined? PRIVATE_CONSTANT_MODULE 32 end 33 34 module Nested 35 def self.private_constant_from_scope 36 PRIVATE_CONSTANT_MODULE 37 end 38 39 def self.defined_from_scope 40 defined? PRIVATE_CONSTANT_MODULE 41 end 42 end 43 end 44 45 class PrivConstClass 46 PRIVATE_CONSTANT_CLASS = true 47 private_constant :PRIVATE_CONSTANT_CLASS 48 49 def self.private_constant_from_self 50 PRIVATE_CONSTANT_CLASS 51 end 52 53 def self.defined_from_self 54 defined? PRIVATE_CONSTANT_CLASS 55 end 56 57 module Nested 58 def self.private_constant_from_scope 59 PRIVATE_CONSTANT_CLASS 60 end 61 62 def self.defined_from_scope 63 defined? PRIVATE_CONSTANT_CLASS 64 end 65 end 66 end 67 68 class PrivConstModuleChild 69 include PrivConstModule 70 71 def private_constant_from_include 72 PRIVATE_CONSTANT_MODULE 73 end 74 75 def defined_from_include 76 defined? PRIVATE_CONSTANT_MODULE 77 end 78 end 79 80 class PrivConstClassChild < PrivConstClass 81 def private_constant_from_subclass 82 PRIVATE_CONSTANT_CLASS 83 end 84 85 def defined_from_subclass 86 defined? PRIVATE_CONSTANT_CLASS 87 end 88 end 89 90 def self.reset_private_constants 91 Object.send :private_constant, :PRIVATE_CONSTANT_IN_OBJECT 92 end 93end 94 95class Object 96 PRIVATE_CONSTANT_IN_OBJECT = true 97 private_constant :PRIVATE_CONSTANT_IN_OBJECT 98end 99