0
0
Rubyprogramming~10 mins

IRB customization in Ruby - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - IRB customization
Start IRB session
Load .irbrc file if exists
Apply custom settings
User enters commands
Commands run with customizations
Repeat until exit
When IRB starts, it looks for a .irbrc file to load custom settings before running user commands.
Execution Sample
Ruby
require 'irb'
IRB.conf[:PROMPT_MODE] = :SIMPLE
puts "Custom prompt set"
# Start IRB session
IRB.start
This code sets a simple prompt style in IRB and prints confirmation before starting IRB.
Execution Table
StepActionEvaluationResult
1IRB startsCheck for .irbrc fileFound .irbrc, load it
2Load .irbrcExecute custom codeCustom prompt set
3Set IRB.conf[:PROMPT_MODE]Assign :SIMPLEPrompt style changed
4User enters command"puts 'Hello'"Prints Hello
5User enters command"1 + 2"Returns 3
6User exits IRBExit commandIRB session ends
💡 User types exit or Ctrl+D to end IRB session
Variable Tracker
VariableStartAfter Step 2After Step 3Final
IRB.conf[:PROMPT_MODE]defaultdefault:SIMPLE:SIMPLE
Key Moments - 2 Insights
Why doesn't my IRB customization work when I start IRB?
Make sure your .irbrc file is in your home directory and has correct Ruby syntax. See step 1 and 2 in the execution_table where IRB loads .irbrc.
How do I change the IRB prompt style?
Set IRB.conf[:PROMPT_MODE] to a symbol like :SIMPLE or :DEFAULT in your .irbrc file as shown in step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of IRB.conf[:PROMPT_MODE] after step 3?
Anil
B:DEFAULT
C:SIMPLE
Dfalse
💡 Hint
Check variable_tracker row for IRB.conf[:PROMPT_MODE] after step 3
At which step does IRB load the .irbrc file?
AStep 2
BStep 1
CStep 3
DStep 4
💡 Hint
Look at the action column in execution_table for loading .irbrc
If you remove the .irbrc file, what happens at step 2?
AIRB loads default settings
BIRB skips customization
CIRB crashes
DIRB prompts for file location
💡 Hint
Step 2 shows loading .irbrc; no file means skipping customization
Concept Snapshot
IRB customization uses a .irbrc file in your home directory.
Put Ruby code there to change IRB behavior.
Common changes: prompt style, history saving.
IRB loads .irbrc automatically on start.
If no .irbrc, IRB uses defaults.
Use IRB.conf hash to set options.
Full Transcript
When you start IRB, it looks for a file named .irbrc in your home folder. If it finds this file, it runs the Ruby code inside it. This lets you change how IRB works, like changing the prompt style or saving command history. For example, setting IRB.conf[:PROMPT_MODE] to :SIMPLE changes the prompt to a simpler style. If IRB does not find .irbrc, it just uses the default settings. You can type commands as usual, and IRB will run them with your custom settings. To stop IRB, type exit or press Ctrl+D.