Skip to content
On this page

Ruby

Version

Running on Ruby v3.3.0

Supported languages

Ruby

Testing framework

RSpec

Special reminders and implementation details

rb
require 'rspec'
require_relative './HelloWorld'

RSpec.describe 'hello function' do
  it 'should return "Hello, world!"' do
    expect(hello).to eq('Hello, world!')
  end
end
1
2
3
4
5
6
7
8

Included libraries

How to debug

Debugging Ruby code is crucial for every developer. One of the simplest yet effective ways to debug is by using puts statements.

Steps to Debug Using puts Statements

  1. Identify the Problem Area: Locate the section of your code where you suspect the problem might be.

  2. Insert puts Statements: Add puts statements before and after the suspected problematic code to print out variable values and flow control.

  3. Check the Results Output of your tests

  4. Analyze the Output: Look at the values printed on the results console to understand what's going wrong in your code. Adjust your code based on the findings and repeat as necessary.

Here’s an example of how to use puts for debugging:

rb
def calculate_and_log_sum(a, b)
  puts "Function called with arguments: #{a}, #{b}" # Log function call
  sum = a + b
  puts "Sum after addition: #{sum}" # Log sum calculation
  sum
end
1
2
3
4
5
6