From: Thomas Wieczorek Date: 2008-03-03T17:54:49+09:00 Subject: Re: Understanding ruby classes You can use Object.const_get(klass) to get the Class class of every defined Ruby class(in your scope). Try this: class MyPrint def printHDR raise NotImplementedError end end class MyPrint2HTML def printHDR puts "I am HTML" end end class MyPrint2PDF def printHDR puts "I am PDF" end end class MyPrintFactory def self.getPrinter(options = {}) printer = nil if options.empty? || !options.key?(:format) raise ArgumentError.new("no Printer Format given") else begin printer = Object.const_get("MyPrint2" + options[:format].upcase).new rescue NameError => ex raise ArgumentError.new("Unknown Format") end end return printer end end printer = MyPrintFactory.getPrinter :format => 'html' printer.printHDR printer = MyPrintFactory.getPrinter :format => 'pdf' printer.printHDR printer = MyPrintFactory.getPrinter :format => 'doc' printer.printHDR