Ruby How to Make a Script That Continuously Runs

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

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

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

  • Select a script, choose 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 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 Run Shift+F10.

  • Select 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 from the main menu.

    • With the Navigation bar visible (), choose 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:

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

Note that when JRuby is used as the project interpreter, the list of Ruby arguments can include Nailgun argument --ng.

When such a run/debug configuration is launched, RubyMine analyzes the running processes, and does one of the following, depending on the presence of the running Nailgun server:

  • If there is no running Nailgun server, or if there is a Nailgun server on a non-default port, or with a different gemset, then RubyMine suggests to specify the desired port number.

  • If a Nailgun server runs on the default port with the required gemset, RubyMine does nothing.

  • If a Nailgun server runs on a different port with the required gemset, then RubyMine suggests to specify the desired port number.

  • If a Nailgun server runs on the default port with a different gemset, then RubyMine deletes the --ng argument.

Classpath property is added to Nailgun settings.

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: 09 August 2022

arambulamits1964.blogspot.com

Source: https://www.jetbrains.com/help/ruby/running-ruby-scripts.html

0 Response to "Ruby How to Make a Script That Continuously Runs"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel