I need to load a class at runtime, whose name I do not know in advance, but
all I know is a file name.
Say "a.rb" which is
class A
......
end
So I want to do something like (pseudo code)
- load a.rb (this will create the class object for A)
- Somehow access constant "A" and invoke "A.new"
I can think of a few hacks but none of them are elegant.
Is there an idiom for it?
TIA
dynaload does __exactly__ this.
gem install dynaload
-a
···
On Sun, 11 Feb 2007, Nasir Khan wrote:
I need to load a class at runtime, whose name I do not know in advance, but
all I know is a file name.
Say "a.rb" which is
class A
......
end
So I want to do something like (pseudo code)
- load a.rb (this will create the class object for A)
- Somehow access constant "A" and invoke "A.new"
I can think of a few hacks but none of them are elegant.
Is there an idiom for it?
--
we can deny everything, except that we have the possibility of being better.
simply reflect on that.
- the dalai lama
Nasir Khan wrote:
I need to load a class at runtime, whose name I do not know in advance, but
all I know is a file name.
Say "a.rb" which is
class A
......
end
So I want to do something like (pseudo code)
- load a.rb (this will create the class object for A)
- Somehow access constant "A" and invoke "A.new"
I can think of a few hacks but none of them are elegant.
Is there an idiom for it?
# Script
require 'script'
script = Script.load "a.rb"
script::A.new
···
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407