Project

General

Profile

Bug #15758 ยป bug.rb

dux (Dino Reic), 04/08/2019 11:27 AM

 
class Foo
end

class Bar
end

class Baz
class Foo
end
end

###

def report klass
name = "Object.const_defined?('%s')" % klass
exists = Object.const_defined?(klass)
instance = eval klass rescue nil
check = (exists && instance) || (!exists && !instance)? 'ok' : 'ERROR!'

puts [
name.ljust(35),
exists.to_s.ljust(5),
(instance ? instance.to_s : 'nil').ljust(8),
check
].join(' -> ')
end

report 'Foo'
report 'Bar'
report 'Baz'
report 'Naat'
report 'Baz::Foo'
report 'Baz::Bar'
report 'Baz::Naat'
puts '---'
report 'Baz::Foo::Bar::Baz::Foo'
    (1-1/1)