I have this source file structure:
-- root.rb
|
|- root -- |- a.rb
|- b.rb
|- c.rb
In root.rb, there is a class named Root, a.rb contains a class named A, and so on.
I want the Root class to iterate the root fold, and dynamically create instance of class A, B, C.
class Root
def initialize
objs = []
dir = Dir.new('root')
dir.each { |file|
# Here file should be a.rb, b.rb, c.rb, etc.
# I want to dynamically require "a.rb, and create and an object of A.
# I know the following two lines must be wrong,
# Could anybody give me the correct code?
require file
objes << ClassFromFilename(file).new
}
end
end
I'm looking for correct code to do "require" and creating object from file name. Please see code comment for details.
class Foo CollectionModule.register(self) end