From: Robert Klemme Date: 2010-01-26T19:13:12+09:00 Subject: Re: Pass arguments to 'require' 2010/1/26 Xavier Noria : > Ruby takes its arguments from a global array called ARGV. That array > is special because it is initialized by the interpreter, buy from then > on it is a regular mutable array. > > In particular you can modify it: > >  def with_argv(*argv) >    original_argv = ARGV.dup >    ARGV.replace(argv) >    yield >    ARGV.replace(original_argv) >  end This is not exception safe. You'd rather want the restoration in an ensure block. I would also return the result of yield rather than the result of doing ARGV.replace. > You would use that method this way: > >  with_argv(1, 2, 3) do >    require '/opt/ruby/script1' >  end > > Not that it is a good practice, you normall would invoke the scripts > using #system or whatever, but since you say you are not a programmer > that would fit into your current model if you don't feel confident to > explore system. "Require" is not a good tool in this case as it will load a script only once and is primarily intended to be used for loading library code. If at all I would rather use "load". So this would be an alternative def with_args(*args) backup = ARGV.dup begin ARGV.replace(args) yield ensure ARGV.replace(backup) end end Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/