blob: 1fa83256ed5408f77fdbea501cc51534701f514a (
plain)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 | # Constant lookup is cached. assert_equal '1', %q{ CONST = 1 def const CONST end const const } # Invalidate when a constant is set. assert_equal '2', %q{ CONST = 1 def const CONST end const CONST = 2 const } # Invalidate when a constant of the same name is set. assert_equal '1', %q{ CONST = 1 def const CONST end const class Container CONST = 2 end const } # Invalidate when a constant is removed. assert_equal 'missing', %q{ class Container CONST = 1 def const CONST end def self.const_missing(name) 'missing' end new.const remove_const :CONST end Container.new.const } # Invalidate when a constant's visibility changes. assert_equal 'missing', %q{ class Container CONST = 1 def self.const_missing(name) 'missing' end end def const Container::CONST end const Container.private_constant :CONST const } # Invalidate when a constant's visibility changes even if the call to the # visibility change method fails. assert_equal 'missing', %q{ class Container CONST1 = 1 def self.const_missing(name) 'missing' end end def const1 Container::CONST1 end const1 begin Container.private_constant :CONST1, :CONST2 rescue NameError end const1 } # Invalidate when a module is included. assert_equal 'INCLUDE', %q{ module Include CONST = :INCLUDE end class Parent CONST = :PARENT end class Child < Parent def const CONST end new.const include Include end Child.new.const } # Invalidate when const_missing is hit. assert_equal '2', %q{ module Container Foo = 1 Bar = 2 class << self attr_accessor :count def const_missing(name) @count += 1 @count == 1 ? Foo : Bar end end @count = 0 end def const Container::Baz end const const } # Invalidate when the iseq gets cleaned up. assert_equal '2', %q{ CONSTANT = 1 iseq = RubyVM::InstructionSequence.compile(<<~RUBY) CONSTANT RUBY iseq.eval iseq = nil GC.start CONSTANT = 2 } # Invalidate when the iseq gets cleaned up even if it was never in the cache. assert_equal '2', %q{ CONSTANT = 1 iseq = RubyVM::InstructionSequence.compile(<<~RUBY) CONSTANT RUBY iseq = nil GC.start CONSTANT = 2 }
|