RubyMine 2020.1 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, do one of the following:

Run a script with Run Anything

  1. Press Ctrl 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 script from the editor

  • Right-click the editor with the opened script and select Run 'script' from the context menu.

Run a script from the Project view

  • Right-click the script in the Project view Alt+1 and select Run 'script' from the context menu.

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.

  • Click the Run button on the toolbar to run the currently selected run/debug configuration.

  • Select the Run | Run Shift+F10 command from the main menu and select the required configuration.

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 Shift+Alt+F10, then press 0 or select the configuration from the popup and press F4.

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

    Run/Debug Configurations

    For example, you can specify the following settings in the Configuration tab:

    Option

    Description

    Ruby script

    Specify the fully qualified path to a Ruby script to be executed, or click the 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:

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

    • 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 script. 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 ellipsis 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 Ruby interpreter used to run a script. 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 use enable it to run project or scratch Ruby scripts in the Rails context. Learn more from Tutorial: Debug a script in Rails context.

Last modified: 29 May 2020