Newbie question

Hello,

Sorry, it's probably a very basic question, but I can't find the answer on 

the net…

I want to load other ruby files as "plugins" from my program. I thought using 

“require” to load the file, eg:

Dir.open(‘myplugins’).each { |plugin|
next if plugin == ‘.’ || plugin == '…'
puts "now treating plugin #{plugin}"
require ‘myplugins/’ + plugin
# instanciate our class :

eval(‘pluginObject =’ + plugin + ‘.new’)

}

But it fails, apparently because the parameter for require must be CONSTANT:

test.rb:4:in require': ./myplugins/poptv.rb:1: class/module name must be CONSTANT (SyntaxError) from test.rb:4 from test.rb:1:ineach’
from test.rb:1

require (‘myplugins/’ + plugin).freeze does the same.

any idea? shoud I use something else than ‘require’? some form of eval?

thank you,

emmanuel

···


“If there is any kind of God, it’s not in you or in me,
but in the space between us”
– Celine, “Before Sunrise”
(It’s not about what you do, it’s about what you give.)

Emmanuel Touzery wrote:

    But it fails, apparently because the parameter for require must be CONSTANT:

test.rb:4:in require': ./myplugins/poptv.rb:1: class/module name must be CONSTANT (SyntaxError) from test.rb:4 from test.rb:1:in each’
from test.rb:1

require (‘myplugins/’ + plugin).freeze does the same.

any idea? shoud I use something else than ‘require’? some form of eval?

Check out line 1 in poptv.rb.

My bet is that you have started a class or module name with a lowercase
character. It must be a constant, which means it must begin with an
uppercase character.

You don’t have any problem with require, it just pops up in the
backtrace because it was what prompted the offending file to be parsed.

···


([ Kent Dahl ]/)_ ~ [ http://www.stud.ntnu.no/~kentda/ ]/~
))_student
/(( _d L b_/ NTNU - graduate engineering - 5. year )
( __õ|õ// ) )Industrial economics and technological management(
_
/ö____/ (_engineering.discipline=Computer::Technology)

oh, yes, thank you…
i was mislead because i was a bit afraid that require would only accept
constant parameters even before i tried, so when i saw that, i quickly jumped
to conclusions…

thank you again :O)

emmanuel

···

On Friday 18 of April 2003 09:31, Kent Dahl wrote:

Emmanuel Touzery wrote:

    But it fails, apparently because the parameter for require must

be CONSTANT:

test.rb:4:in require': ./myplugins/poptv.rb:1: class/module name must be CONSTANT (SyntaxError) from test.rb:4 from test.rb:1:in each’
from test.rb:1

require (‘myplugins/’ + plugin).freeze does the same.

any idea? shoud I use something else than ‘require’? some form of eval?

Check out line 1 in poptv.rb.

My bet is that you have started a class or module name with a lowercase
character. It must be a constant, which means it must begin with an
uppercase character.

You don’t have any problem with require, it just pops up in the
backtrace because it was what prompted the offending file to be parsed.


“If there is any kind of God, it’s not in you or in me,
but in the space between us”
– Celine, “Before Sunrise”
(It’s not about what you do, it’s about what you give.)