From: David Garamond Date: 2004-02-01T18:30:23+09:00 Subject: check whether a class is defined, listing all classes Given a string of fully-qualified class name, how do I easily check whether the class is defined or not? I hope it's not as 'hard' as I think: def class_defined?(classname) m = Class classname.split("::").each { |c| m.constants.include?(c) or return false m = m.const_get c } return true end p class_defined?("Test::Unit::TestCase") # false require 'test/unit/testcase' p class_defined?("Test::Unit::TestCase") # true Is there an easier way? A bonus question, how do I list all the defined classes in their fully qualified name? Example output: Object String FalseClass Struct Struct::Tms File File::Stat ... (My own code is very ugly, I'm embarrassed to show it :-) -- dave