Bird
0
0

Which ~/.irbrc snippet correctly does this?

hard📝 Application Q15 of 15
Ruby - Ecosystem and Best Practices
You want to customize IRB so that it automatically requires the 'json' library, sets a custom prompt showing the current time, and saves 500 commands in history. Which ~/.irbrc snippet correctly does this?
Arequire 'json' IRB.conf[:PROMPT][:CUSTOM] = { PROMPT_I: "[#{Time.now.strftime('%H:%M:%S')}] > " } IRB.conf[:PROMPT_MODE] = :CUSTOM IRB.conf[:SAVE_HISTORY] = 500
Brequire 'json' IRB.conf[:PROMPT_MODE] = :SIMPLE IRB.conf[:SAVE_HISTORY] = '500'
Cload 'json' IRB.conf[:PROMPT_MODE] = :DEFAULT IRB.conf[:SAVE_HISTORY] = 500
Drequire 'json' IRB.conf[:PROMPT_MODE] = :CUSTOM IRB.conf[:SAVE_HISTORY] = 1000
Step-by-Step Solution
Solution:
  1. Step 1: Load the 'json' library correctly

    Use require 'json' to load the library automatically.
  2. Step 2: Define a custom prompt with current time

    Set IRB.conf[:PROMPT][:CUSTOM] with a prompt string showing current time using Ruby's Time.now.strftime.
  3. Step 3: Set prompt mode and save history

    Assign IRB.conf[:PROMPT_MODE] = :CUSTOM to use the custom prompt and set IRB.conf[:SAVE_HISTORY] = 500 as an integer to save 500 commands.
  4. Final Answer:

    require 'json', custom prompt with current time, :CUSTOM mode, SAVE_HISTORY = 500 -> Option A
  5. Quick Check:

    Require json, custom prompt with time, save 500 history [OK]
Quick Trick: Combine require, custom prompt hash, and integer history save [OK]
Common Mistakes:
  • Using string instead of integer for history
  • Not defining custom prompt hash properly
  • Using load instead of require for libraries

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes