Challenge - 5 Problems
IRB Customization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
IRB Prompt Customization Output
What will be the output of the following IRB prompt customization code snippet when you start IRB?
Ruby
IRB.conf[:PROMPT][:MY_PROMPT] = {
PROMPT_I: "myirb> ",
PROMPT_S: "myirb%l> ",
PROMPT_C: "myirb* ",
PROMPT_N: "myirb? ",
RETURN: "=> %s\n"
}
IRB.conf[:PROMPT_MODE] = :MY_PROMPT
# Then start IRBAttempts:
2 left
💡 Hint
Look at the PROMPT_I key in the custom prompt hash and the PROMPT_MODE setting.
✗ Incorrect
Setting IRB.conf[:PROMPT][:MY_PROMPT] defines a new prompt style named MY_PROMPT. Assigning IRB.conf[:PROMPT_MODE] = :MY_PROMPT activates it. PROMPT_I defines the main input prompt string, so the prompt will show as 'myirb> '.
🧠 Conceptual
intermediate1:30remaining
Purpose of IRB.conf[:SAVE_HISTORY]
What is the purpose of setting IRB.conf[:SAVE_HISTORY] = 1000 in IRB customization?
Attempts:
2 left
💡 Hint
Think about what 'SAVE_HISTORY' might control in a command line tool.
✗ Incorrect
IRB.conf[:SAVE_HISTORY] controls how many commands IRB remembers in its history file. Setting it to 1000 means IRB will save the last 1000 commands entered.
🔧 Debug
advanced2:30remaining
Fixing IRB Custom Prompt Syntax Error
This IRB customization code causes a syntax error. Which option fixes it correctly?
Ruby
IRB.conf[:PROMPT][:CUSTOM] = {
PROMPT_I: '>> ',
PROMPT_S: '>> ',
PROMPT_C: '>> ',
PROMPT_N: '>> ',
RETURN: '=> %s\n'
}
IRB.conf[:PROMPT_MODE] = :CUSTOMAttempts:
2 left
💡 Hint
Look carefully at the commas between hash entries in Ruby syntax.
✗ Incorrect
In Ruby hashes, each key-value pair must be separated by a comma. The missing comma after PROMPT_N causes a syntax error. Adding it fixes the problem.
❓ Predict Output
advanced2:00remaining
IRB History File Location
Given this IRB configuration snippet, what will be the path of the history file used by IRB?
Ruby
IRB.conf[:HISTORY_FILE] = File.expand_path('~/.my_irb_history')Attempts:
2 left
💡 Hint
File.expand_path with '~' expands to the user's home directory.
✗ Incorrect
File.expand_path('~/.my_irb_history') resolves to the full path of the file named '.my_irb_history' inside the user's home directory. IRB will use this file to save command history.
🚀 Application
expert3:00remaining
Custom IRB Prompt with Dynamic Time
Which option correctly defines a custom IRB prompt that shows the current time before the prompt symbol?
Attempts:
2 left
💡 Hint
The prompt string must be a callable (like a lambda) to update dynamically each time.
✗ Incorrect
To have a dynamic prompt showing current time, PROMPT_I must be a lambda or proc that returns the string with the current time. Option B uses a lambda with Time.now.strftime to format time dynamically. Other options use static strings or incorrect syntax.