From: 7stud -- Date: 2007-11-06T03:29:43+09:00 Subject: Re: Reading a class-file and calling it at runtime. Miss Elaine Eos wrote: > In article > <3736dd30711042349n7225229dw4af74110f2a52048@mail.gmail.com>, > sean.ohalpin@gmail.com wrote: > >> only the last call to some_method fails. Have you checked that the >> name of the class is correct or if you are defining your plugin class >> within a module? > > I am NOT using "module." I guess I need to go read-up on modules -- > Thanks! :) Maybe you should post a simplified version of one of the files you are requiring, e.g. class Dog def speak puts "Woof woof" end end As this example shows: >Sean O'halpin wrote: > > # ./myplugin.rb > > class MyPlugin > def some_method > puts "Hi from #{self}!" > end > end > >--------------- > > # test-require-plugin.rb > > one_plugin = "myplugin" > PLUG_IN_DIR = '.' > plugin_class_name = "MyPlugin" > > require "#{PLUG_IN_DIR}/#{one_plugin}" > plugin_class = Object.const_get(plugin_class_name).new > plugin_class.some_method > > # output > Hi from #! ...you don't need to have your class inside a module to get your code to work. But the rest of the example showed that IF your class definition is inside a module, then you have to alter your syntax a little to retrieve the class with const_get. Here is another example if it helps (all files are in the current directory): #plugin.rb: class Dog def speak puts "Woof woof" end end #my_program.rb: require 'plugin' dog_class = Object.const_get("Dog") dog = dog_class.new dog.speak -- Posted via http://www.ruby-forum.com/.