RubyMine 2019.3 Help

Running 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 without configuring

To run a specified Ruby script (for example, script.rb) for the first time, do one of the following:

  • Press Ctrl twice and type the following command:

    ruby script.rb

    Press Enter.

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

  • Right-click the script in the project tool window 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:

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

Last modified: 5 December 2019