From: Troy Denkinger Date: 2006-03-02T08:30:04+09:00 Subject: Dynamic Object Instantiation ------=_Part_6773_210397.1141255788198 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I'm sure this question has been asked and answered in the past, but googlin= g and searching the list archives isn't getting me much. It's probably a cas= e of me not searching correctly. So, if someone has a pointer on that front, let me know. Basically, I want a class to dynamically load and instantiate objects. Here's the code that is supposed to do that: ComponentGatherer.rb --------------------------------- class ComponentGatherer def initialize() @@components =3D [] Dir.foreach( File.dirname( __FILE__ ) ){|x| next unless x =3D~ /component.rb$/i x.gsub!( ".rb", "" ) require "#{x}" @@components.push( x ) } end def components @@components.each{ |x| test =3D x.new() # Blah, blah, blah } end end Locating and requring the files seems to be working fine, it's when the component() call is made that I'm a bit lost. I have to *Component.rbfiles, they look like this: MyOtherComponent.rb -------------------------------- class MyOtherTestComponent attr :test def initialize() self.test =3D 2 end end The error I get from the components() method is: undefined method `new' for "MyOtherTestComponent":String (NoMethodError) I understand what the error is saying, but I'm not sure how to call new() o= n "x" above such that it returns an object of the requested class. Any help is appreciated. Regards, Troy Denkinger ------=_Part_6773_210397.1141255788198--