How to pass commandline arguments to a file loaded with "irb -rfile" ?

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

Hi, I run "irb -r myfile.rb" and would like "myfile.rb" to receive commandl=
ine=20
arguments, and these not to conflict with irb parameters.

Is it possible? I couldn't get it. What I'd like is something as:

~# irb -r myfile.rb -p 9898 -s lala

so ARGVinspected in "myfile.rb" would contain:
["-p", "9898", "-s", "lala"]

Is it possible? Thanks a lot.

=2D-=20
I=C3=B1aki Baz Castillo <[email protected]>
 
R

Robert Klemme

2009/12/23 I=F1aki Baz Castillo said:
Hi, I run "irb -r myfile.rb" and would like "myfile.rb" to receive comman= dline
arguments, and these not to conflict with irb parameters.

Is it possible? I couldn't get it. What I'd like is something as:

~# irb -r myfile.rb -p 9898 -s lala

so ARGVinspected in "myfile.rb" would contain:
["-p", "9898", "-s", "lala"]

Is it possible? Thanks a lot.

#require is not build to pass arguments around - neither is #load.
One of the reasons is that you do not know whether the file is
actually loaded at that moment.

The easier solution is probably to do it the other way round: build a
script which processes arguments and then fires off IRB. You can look
at your "irb" script to get a starting point how to do that. The you
would do

myfile.rb -p 9898 -s lala

and receive an IRB prompt.

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
I

Iñaki Baz Castillo

El Mi=E9rcoles, 23 de Diciembre de 2009, Robert Klemme escribi=F3:
2009/12/23 I=F1aki Baz Castillo said:
Hi, I run "irb -r myfile.rb" and would like "myfile.rb" to receive
commandline arguments, and these not to conflict with irb parameters.

Is it possible? I couldn't get it. What I'd like is something as:

~# irb -r myfile.rb -p 9898 -s lala

so ARGVinspected in "myfile.rb" would contain:
["-p", "9898", "-s", "lala"]

Is it possible? Thanks a lot.
=20
#require is not build to pass arguments around - neither is #load.
One of the reasons is that you do not know whether the file is
actually loaded at that moment.
=20
The easier solution is probably to do it the other way round: build a
script which processes arguments and then fires off IRB. You can look
at your "irb" script to get a starting point how to do that. The you
would do
=20
myfile.rb -p 9898 -s lala
=20
and receive an IRB prompt.

It makes lot of sense. Thanks a lot.


=2D-=20
I=F1aki Baz Castillo <[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top