0
0
Rubyprogramming~10 mins

IRB for interactive exploration in Ruby - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - IRB for interactive exploration
Start IRB
Prompt user input
Evaluate input code
Display result
Wait for next input
Loop back to Prompt user input
Exit IRB on command
Loop back to Prompt user input
IRB starts and waits for your code input, runs it, shows the result, then waits again until you exit.
Execution Sample
Ruby
irb(main):001:0> 2 + 3
=> 5
irb(main):002:0> puts 'Hi!'
Hi!
=> nil
This shows typing code in IRB, it runs and shows the output immediately.
Execution Table
StepUser InputEvaluationOutputNext Action
12 + 3Calculate sum5Prompt next input
2puts 'Hi!'Print stringHi!Prompt next input
3exitExit commandSession endsStop IRB
💡 User types 'exit' to end the IRB session
Variable Tracker
VariableStartAfter Step 1After Step 2Final
_ (last result)nil5nilnil
Key Moments - 3 Insights
Why does IRB show '=> 5' after I type '2 + 3'?
IRB evaluates your expression and shows the result with '=>'. This is shown in execution_table step 1 under Output.
Why does 'puts' print output but return nil?
'puts' prints text to the screen but returns nil, so IRB shows 'Hi!' as output and '=> nil' as the return value, seen in execution_table step 2.
How do I stop IRB?
Typing 'exit' or pressing Ctrl+D ends the session, as shown in execution_table step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the output after step 1?
Anil
B2 + 3
C5
DHi!
💡 Hint
Check the Output column in execution_table row 1
At which step does IRB stop running?
AStep 3
BStep 2
CStep 1
DNever stops
💡 Hint
Look at the Next Action column in execution_table
If you type 'puts "Hello"' in IRB, what will the return value be?
A"Hello"
Bnil
Cputs
DError
💡 Hint
See execution_table step 2 and variable_tracker for 'puts' behavior
Concept Snapshot
IRB lets you type Ruby code and see results instantly.
Type code, press Enter, see output with '=>'.
Use 'exit' to leave IRB.
Useful for quick testing and learning Ruby.
Full Transcript
IRB is an interactive Ruby shell. You start it and get a prompt. You type Ruby code, press Enter, and IRB runs it immediately. It shows the result with a '=>' sign. For example, typing '2 + 3' shows '=> 5'. If you use 'puts', it prints text but returns nil, so IRB shows the printed text and then '=> nil'. You keep typing commands and seeing results until you type 'exit' to stop IRB. This makes it easy to explore Ruby code step by step.