1

I'm examining how ridk enable works in order to figure out how to hook it into Travis CI build logic. (The Ruby installation I'm studying is a RubyInstaller+Devkit installed locally; the commands are run from the "Start Command Prompt with Ruby" prompt.)

I've got stuck at a Ruby command line executed under the hood whose working is a mystery to me:

"C:\Ruby24-x64\bin\ruby" --disable-gems -x 'C:\Ruby24-x64\bin\ridk.cmd' enable

It seems to run a CMD script (?!) with Ruby -- which isn't supposed to be possible. Running it with -rtracer in place of --disable-gems shows that the execution somehow ends up jumping into C:/Ruby24-x64/lib/ruby/site_ruby/2.4.0/ruby_installer/runtime/ridk.rb.

Could someone explain to me how this command line works?

1 Answer 1

2

From man ruby:

-x[directory]
Tells Ruby that the script is embedded in a message. Leading garbage will be discarded until the first line that starts with #! and contains the string, ruby
Any meaningful switches on that line will be applied. The end of the script must be specified with either EOF ^D ( control-D ^Z ( control-Z or the reserved word __END__ If the directory name is specified, Ruby will switch to that directory before executing script.

Which means the ridk.cmd has embedded ruby code.

The directory is optional, as indicated by both the square brackets around the name and the description. If provided, it should be directly after -x without any space, which effectively allows it to be an optional argument.

Sign up to request clarification or add additional context in comments.

5 Comments

But it says "directory", and C:\Ruby24-x64\bin\ridk.cmd is not a directory...
Oh, I see, the "directory" is only recognized if it's specified directly after -x without space. This is contrary to the standard practice, it usually doesn't matter if there's a space or not.
(See? Even you missed that tiny-but-critical detail when copypasting the help text!)
Ruby starts evaluating ridk.cmd at line 37 – the first line starting with #! and containing the word ruby
@ivan_pozdeev I did not judge this necessary for the answer, but I'm gonna add it anyway, it's true that the description is not entirely explicit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.