On Mar 17, 2011, at 2:14 AM, Nikolai Weibull wrote:

> Hi!
> 
> Why has defined? been changed for autoloaded constants in 1.9?
> 
> In 1.8 the following prints "constant":
> 
> autoload :A, 'a'
> puts defined?(A)
> 
> In 1.9 it prints nil.
> 
> Why the change?  I can see how it makes sense, sort of, but I have a test for
> 
> defined? ::Gem::Specification
> 
> to test whether RubyGems has been loaded.
> 
> How do I perform this test in 1.9?  (I could of course change the test
> to the less restrictive defined? ::Gem, but I want to know if there√‘
> a new way one should use for performing tests for loaded features like
> this one.)

Just check for Gem.

$ ruby -v -e 'p Object.const_defined?(:Gem)'
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.6.0]
true
$ ruby --disable-gems -v -e 'p Object.const_defined?(:Gem)'
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.6.0]
false