Previous ToC Up Next

3. Four Ways to Invoke Ruby

3.1. standard way:

In order to run a program some_code.rb, type

  ruby some_code.rb
This will work for running files that are present in the current directory.

The drawback is that invoking ruby does not give you access to files that are installed in the source libraries such as $ACSROOT/bin and $ACSROOT/kali/bin.

3.2. the acs and kali commands:

As an abbreviation for ruby -S, we have introduced the alternatives:

  acs some_code.rb

  kali some_code.rb
The command acs includes a search for files in the general source directory $ACSROOT/bin. In addition to that, the command kali also includes a search for files in the kali specific source directory $ACSROOT/kali/bin.

Note that, when using either of these two commands, you can leave out the .rb suffix. The two commands

  acs some_code

  kali some_code
give the same results as the two commands listed above.

3.3. executing the command directly:

In most cases, the Ruby files have been made executable (and if not, you can make them executable by typing chmod +x some_code.rb). You can then run a code by directly type its file name:

If you want to run files in the source directories in this way, you have to add the appropriate directories, other than $ACSROOT/bin (such as $ACSROOT/kali/bin) explicitly to your command search path.

3.4. using a wrapper:

Another way to execute the file some_code.rb is to write a one-line shell script, with the name some_code and containing just one line:

  kali $*
which can then be invoked simply as

The presence of $* in the one-liner will guarantee that all command line options will be passed on correctly, as in:

  kali some_code --help some_option other_option

3.5. Conclusions

The first way doesn't work for files in source libraries. The last two ways are dangerous, in the sense that they introduce the name of all our Ruby files into the global name space, where they can easily collide with other packages. Therefore, our prefered way to run Ruby files in the Kali project is to use the second way:

  kali some_code
Note that the command kali can be used everywhere where one can use acs or just plain ruby.

Note, however, that there are still occasions to use ruby instead of kali in some situations. For example, when you are editing the file some_name.rb in a particular directory, and you want to test it out, you want to run it locally, ignoring the older official version in the kali source directory. In this case you can type:

  ruby some_code.rb
However, you can also type:

  kali some_code.rb
or alternatively just

  kali some_code
since the kali command is guaranteed to first look in the current directory for a file to execute.

So it is up to the user, which one to use. If you don't want to think about what file is located where, you can always use the kali command, since that is always guaranteed to do the right thing. However, if the ruby command can find the intended file (and the required files specified by require) it would be perfectly fine to use the standard ruby command instead. And if you do not mind the potential hazards of using the global name space, you can of course use the third or fourth way listed above.
Previous ToC Up Next