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:
Syntax
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)
# Simulating what you'd see interacting with irb:
puts "2 + 2 = #{2 + 2}"
puts "In irb, typing '2 + 2' alone would print '=> 4' automatically"
Login to try C/C++/Java/PHP code in the editor
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
- Typing a multi-line method in IRB and pressing Enter early, ending the definition too soon.
- Assuming variables stay after leaving IRB, when the session state is lost on
exit. - Expecting
=> 4to be printed output, when it is the return value of the expression, whileputsoutput has its own line.
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: