RubyMine 2023.2 Help

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 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

  1. Press Control twice to invoke the Run Anything popup.

  2. Type the ruby script.rb command and press Enter.

    Run ruby script

    If necessary, you can specify the required command-line options and script arguments.

  3. (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 Control+Shift+F10.

  • Right-click a script and select Run 'script' from the context menu.

  • Select Run | Run... Alt+Shift+F10 from the main menu, select script from the list and press Enter.

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 Control+Shift+F10.

  • Right-click a script and select Run 'script' from the context menu.

  • Select a script, choose Run | Run... Alt+Shift+F10 from the main menu, select script from the list and press Enter.

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 Control 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 Run Shift+F10.

  • Select Run | Run... Alt+Shift+F10 from the main menu, 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:

  1. Open the Run/Debug Configuration dialog in one of the following ways:

    • Select Run | Edit Configurations from the main menu.

    • With the Navigation bar visible (View | Appearance | Navigation Bar), choose Edit Configurations from the run/debug configuration selector.

      Edit run configurations
    • Press Alt+Shift+F10 and then press 0.

  2. In the opened Run/Debug Configurations dialog, select the required configuration in the Ruby group, and specify its settings.

    Run/Debug Configurations

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 clickthe Browse button, 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 ARGV array. For example:

  1. Pass the following values as Script arguments: "Jet" "Brains".

  2. Run the following Ruby script:

    puts "Hello, #{ARGV.join}! I'm Ruby!"

    A program will return Hello, JetBrains! I'm Ruby!.

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 the Browse button 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.

Last modified: 28 October 2021