Run Ruby scripts
RubyMine allows you to quickly run or debug Ruby scripts from the editor or by using the configured set of parameters - run/debug configurations. For instance, you can specify the following parameters for the Ruby run/debug configuration: script arguments, environment variables, additional command-line arguments, and so on.
In this topic we'll show you how to:
Run a Ruby script for the first time without a run configuration
Run a Ruby script with a run configuration
Configure additional parameters for running a script
Run a script
To run a specified Ruby script (for example, script.rb) for the first time, choose one of the following ways:
Run a script with Run Anything
Press Ctrl twice to invoke the Run Anything popup.
Type the
ruby script.rb
command and press Enter.If necessary, you can specify the required command-line options and script arguments.
(Optional) To run scratch files or scripts outside the project root, hold down the Alt key before running the command (in this case, the dialog title is changed to Run in Context).
Run a currently opened script
To run a script opened in the editor, do one of the following:
Press Ctrl+Shift+F10.
Right-click a script and select Run 'script' from the context menu.
Select script from the list and press Enter.
Alt+Shift+F10 from the main menu, select
Run a script from the Project view
To run a script from the Project view Alt+1, choose one of the following ways:
Select a script and press Ctrl+Shift+F10.
Right-click a script and select Run 'script' from the context menu.
Select a script, choose script from the list and press Enter.
Alt+Shift+F10 from the main menu, select
After you've run a Ruby script, RubyMine automatically creates a special profile - a temporary run/debug configuration. You can customize settings of this configuration, for example, pass command line arguments, configure environment variables, and so on. Then, you can save the customized configuration to quickly run this configuration in the future.
Run a script using a run/debug configuration
You can run the Ruby script with the existing run/debug configurations in one of the following ways:
Press Ctrl twice to invoke the Run Anything popup. Start typing the required configuration name, select it from the list, and press Enter.
Select the desired configuration on the toolbar and click Shift+F10.
Go to
Alt+Shift+F10 and select the desired configuration from the list and press Enter.
Configure parameters for running a script
When you run a Ruby script for the first time, RubyMine automatically creates a corresponding Ruby temporary configuration, which can be saved. If necessary, you can create the Ruby run/debug configuration manually from the predefined template.
To customize the run/debug configuration, do the following:
Open the Run/Debug Configuration dialog in one of the following ways:
Select
from the main menu.With the Navigation bar visible ( ), choose from the run/debug configuration selector.
Press Alt+Shift+F10 and then press 0.
In the opened Run/Debug Configurations dialog, select the required configuration in the Ruby group, and specify its settings.
Run/debug configuration: Ruby
Configuration tab
Item | Description |
---|---|
Name | In this field, specify the name of the current run/debug configuration. |
Ruby script | Specify the fully qualified path to a Ruby script to be executed, or click , and select the desired Ruby script in the dialog that opens. |
Script arguments | Specify command-line arguments that will be passed after the script's filename. These arguments will be available to your Ruby program in the global
|
Working directory | Specify the working directory used by the running task. For example, this option is in effect when the running script loads other scripts by relative paths. |
Environment variables | Specify the list of environment variables as the name-value pairs, separated with semi-colons. Alternatively, click to create variables and specify their values in the Environment Variables dialog. |
Ruby arguments | Specify the command-line arguments to be passed to the Ruby interpreter. |
Ruby SDK | Specify the desired Ruby interpreter. You can choose the project default Ruby SDK, or select a different one from the list of configured Ruby SDKs. |
Execute in the context of Rails | This option is available for scripts in Rails applications. You can enable it to run scratch or project Ruby scripts in the Rails context. Learn more from Tutorial: Debug a script in Rails context. |