From: Sai Hl Date: 2009-02-17T03:38:41+09:00 Subject: Re: load a Ruby source with params Brian Candler wrote: > (1) Loading in more Ruby code to the currently-running Ruby interpreter. > This is done using "load" or "require". There is no concept of > "parameters" here. However you could set a global variable (e.g. $foo) > or a constant (Foo), which the code in the other file makes use of. > > But it would be more normal for the other file just to define modules or > classes, and then after the load has completed you invoke one of those > modules or classes, at which point you can pass whatever parameters you > like. > > (2) Forking and execing a new child process. This could be another > Ruby interpreter, but it could also be any other program on your system. > When you do this, you can pass command-line arguments (and/or > environment variables and open files) > > The simplest way is with Kernel#system, e.g. > > system("/bin/prog","arg1","arg2") > > but other options include backticks, IO.popen, the open3 and open4 > libraries, and the low-level Kernel#fork and Kernel#exec calls. Many thanks for your detailled answer, Brian Candler. until now I used those few lines: # inc.test.rb 'Hello ' + subject # inc.other_test.rb 'Hi, ' + subject # main.rb @files = [] subject = 'World' Dir['inc.*.rb'].each do |file| open(file) { |f| @files << f.read } end @files.each { |f| puts "#{eval(f)}" } But it's true that the eval function takes a lot of ressources and the (1) solution is better, using global variables. I am going to try to use the (2) solutions, with a module for any files like: # inc.test.rb module Inc def say 'Hello' + subject end end But is this possible in my case, because I don't know the name of each module (which is depend of the name of its file)? Regards -- Posted via http://www.ruby-forum.com/.