2

When I set the load path on command line using -I, is it ALWAYS the case that this path is the first item in the $: array?

Is it ever possible that this path is NOT the first item in the $: array?

1
  • Not sure, but it's a pretty safe bet that if you shift your path at the top of your script, that it's going to be the first. Unless you're code does more shifting later. Commented Nov 22, 2010 at 23:41

1 Answer 1

2

That mostly depends on version of Ruby interpreter/virtual machine you're using, but, generally, that's the purpose of -I option: you should be able to override default $LOAD_PATH with it.

If you want to supply $LOAD_PATH components using command-line that would be applied in other position, you're free to implement your own command-line options, such as

require 'getoptlong' opts = GetoptLong.new(['--include', '-I', GetoptLong::REQUIRED_ARGUMENT ]) opts.each { |opt, arg| $LOAD_PATH << arg if opt == '--include' } 
Sign up to request clarification or add additional context in comments.

2 Comments

do you have any info on how portable that statement is?
It depends on how you define "portable". Both using -I in command line of Ruby interpreter/virtual machine and using some other command-line option from application itself (as done in this example) is portable across operating systems and various Ruby versions. The behavior of $LOAD_PATH is well-defined. However I suspect that some versions (or platforms) might lack command-line (for example, I'm not sure that you can start a program with command-line arguments on Android platform or in S60 port).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.