anne001
7/5/2006 1:11:00 PM
I am trying to use the catapult code.
If I move the FooBar.rb file in the lib directory, Catapult serves the
FooBar code fine.
If I copy the FooBar class in the catapult.rb file, Catapult fails.
Yet the FooBar class is the same in both case, and the code calling
Object.const_get is the same in both case, the only difference is that
when the program reads from file, it runs require cname first.
What could be the problem with Object.const_get when the class is
defined in the same file as the Objec.const_get request?
this is the section of catapult code involved:
def self.new_from_name( class_name )
cname = String.new( class_name.untaint )
obj = nil
begin
obj = Object.const_get( cname ).new()
rescue Exception
begin
require cname
obj = Object.const_get( cname ).new
rescue Exception
raise "Error: Cannot create object #{cname}: #{$!}
Tried loading from \n#{$:.join( "\n")}" unless obj
end
end
obj
end
class FooBar
def run( path )
"<html>This is FooBar!<br/>We have path #{path}</html>"
end
def content_type
"text/html"
end
end