R
Rick DeNatale
Bear in mind that if the shell started the program and the program
specified on the shebang line wasn't the ruby interpreter, the code
quoted above doesn't run.
Since it is running, somehow the ruby interpreter has been started and
given a file containing text that may or may not actually be Ruby code.
This could happen if you started ruby by explicitly executing the "ruby"
command, or if you're running on Windows where there is no shell to do
shebang interpreting for you.
That bit of code inspects the shebang line and, if the word "ruby"
doesn't appear on the line, it tries to execute what it assumes is a
program.
Actually what that code does is:
If the first line is a shebang
if it doesn't contain 'ruby' somewhere
extract the path which it seems to be wanting to run
produce a fatal error
else
extract any arguments for the ruby command
continue to process.
end
end
So it is trying to avoid accidentially running, say a bash or perl
script using the ruby interpreter.