From: Robert Klemme Date: 2004-02-01T21:39:50+09:00 Subject: Re: check whether a class is defined, listing all classes "David Garamond" schrieb im Newsbeitrag news:401CEDC9.8000804@zara.6.isreserved.com... > Robert Klemme wrote: > >> p class_defined?("Test::Unit::TestCase") # false > >> require 'test/unit/testcase' > >> p class_defined?("Test::Unit::TestCase") # true > >> > >>Is there an easier way? > > > > irb(main):009:0> defined? Test::Unit::TestCase > > => nil > > irb(main):010:0> require 'test/unit/testcase' > > => true > > irb(main):011:0> defined? Test::Unit::TestCase > > => "constant" > > But what if the class name to be checked is a string? > ("Test::Unit::TestCase")? irb(main):005:0> eval "defined? " + "Test::Unit::TestCase" => nil irb(main):006:0> require 'test/unit/testcase' => true irb(main):007:0> eval "defined? " + "Test::Unit::TestCase" => "constant" > Btw, is "defined?" a method (of what class?)? > A statement? It's an operator: http://www.rubycentral.com/book/tut_expressions.html > >>A bonus question, how do I list all the defined classes in their fully > >>qualified name? Example output: > > > > ObjectSpace.each_object( Class ){|cl| p cl} > > ObjectSpace.each_object( Class ){|cl| p cl.name} > > Ah, Class#name... Thanks, I'm so glad it's straightforward & easy. :-) robert