RubyMine 2024.1 Help

Tutorial: Debug in IRB/Rails console

After you have run the IRB or Rails console, RubyMine creates a temporary run/debug configuration. This configuration allows you to rerun the console or launch it in the debug mode. In this tutorial, we'll show you how to load and debug specific parts of code in the IRB console.

A sample Ruby application used in this tutorial has two files - script.rb and song.rb. We'll debug the to_s method called for the newly created Song object.

require './song' puts Song.new("My Way", "Sinatra").to_s
class Song def initialize(name, artist) @name = name @artist = artist end def to_s "Song: #{@name}--#{@artist}" end end

Perform the following steps to debug this program code in the IRB console.

  1. Open the song.rb file and set the breakpoint within the to_s method as follows.

    Set breakpoint
  2. Run the IRB console configuration in the debug mode. To do this, select this configuration on the main toolbar and click the Debug button.

    Debug IRB console
  3. In the opened song.rb file, place the caret at any line and select Tools | Load File/Selection into IRB/Rails Console from the main menu. This will load code from the file to the IRB console.

  4. Open the script.rb file and select the to_s method call as follows.

    Select code

    Then, select Tools | Load File/Selection into IRB/Rails Console from the main menu. RubyMine loads this selection to the IRB console and stops program execution at the breakpoint.

    Debugger

    In the invoked Debug tool window, you can investigate the application state: frames, variable values, and so on. Learn more at Examine suspended program.

Last modified: 08 April 2024