What about something like this?

defined?(Gem) && Gem.const_defined?(:Specification)

// Magnus Holm


On Thu, Mar 17, 2011 at 10:14, Nikolai Weibull <now / bitwi.se> 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”Ēs
> a new way one should use for performing tests for loaded features like
> this one.)
>
> Thanks!
>
>