← Back to Ruby Course | Chapter 1: Setup & Basics | Lesson 3 of 7

IRB (Interactive Ruby)

IRB is a chat window for Ruby where you type a line and get an answer at once. It is like a scratch pad for trying ideas out.

In this page:

  1. IRB (Interactive Ruby)
Syntax
ruby
irb
irb(main):001> expression

IRB (Interactive Ruby)

IRB is Ruby's interactive console, started by typing irb in a terminal, where you can type expressions and see results immediately. It's the fastest way to experiment with small snippets of Ruby without creating a file.

Every expression's result is automatically printed, similar to a calculator.

Note: Type exit or press Ctrl+D to leave an IRB session.

Example: IRB (Interactive Ruby)

markup
# Simulating what you'd see interacting with irb:
puts "2 + 2 = #{2 + 2}"
puts "In irb, typing '2 + 2' alone would print '=> 4' automatically"
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Typing a multi-line method in IRB and pressing Enter early, ending the definition too soon.
  2. Assuming variables stay after leaving IRB, when the session state is lost on exit.
  3. Expecting => 4 to be printed output, when it is the return value of the expression, while puts output has its own line.
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.