I am confused about Ruby command-line options. Both -C dir
and -X dir
remove directory, but how do they differ from each other?
-x [dir]
differ from -X dir
?-I dir
do (I know that it adds dir
as the directory for loading libraries)?Let's create a test.rb file in home directory with following:
hello
#!/usr/bin/ruby
p "here"
Now if we try to run it:
ruby -C /home/my_home test.rb
Which means change working directory to /home/my_home and run test.rb you will get an error:
test.rb:1:in `<main>': undefined local variable or method `hello' for main:Object (NameError)
If we run it with:
ruby -x /home/my_home test.rb
We will get "here" printed and get no error. The main difference between -x and -C is that -x removes everything before the #!/usr/bin/ruby
line. And you don't have to set directory to cd too, when using -x. Because the main purpose of -x is to remove lines and it just includes -C functionality too, if needed.
cd /home/my_home; ruby -x test.rb
See (ruby --help)
As for -I. You can provide the directories that ruby will search for the file you execute or require.
ruby -x test.rb
Ruby will not find the test.rb file unless you are in /home/my_home. But if you add -I ruby will look for test.rb in "/home/my_home" too.
ruby -x -I/home/my_home test.rb
The difference with -C is that it will not change directory before executing, but will just search for files there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With