Ruby - Ecosystem and Best PracticesYou 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] = 500Brequire 'json' IRB.conf[:PROMPT_MODE] = :SIMPLE IRB.conf[:SAVE_HISTORY] = '500'Cload 'json' IRB.conf[:PROMPT_MODE] = :DEFAULT IRB.conf[:SAVE_HISTORY] = 500Drequire 'json' IRB.conf[:PROMPT_MODE] = :CUSTOM IRB.conf[:SAVE_HISTORY] = 1000Check Answer
Step-by-Step SolutionSolution:Step 1: Load the 'json' library correctlyUse require 'json' to load the library automatically.Step 2: Define a custom prompt with current timeSet IRB.conf[:PROMPT][:CUSTOM] with a prompt string showing current time using Ruby's Time.now.strftime.Step 3: Set prompt mode and save historyAssign IRB.conf[:PROMPT_MODE] = :CUSTOM to use the custom prompt and set IRB.conf[:SAVE_HISTORY] = 500 as an integer to save 500 commands.Final Answer:require 'json', custom prompt with current time, :CUSTOM mode, SAVE_HISTORY = 500 -> Option AQuick 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 historyNot defining custom prompt hash properlyUsing load instead of require for libraries
Master "Ecosystem and Best Practices" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Functional Patterns in Ruby - Lazy enumerators - Quiz 11easy Metaprogramming Fundamentals - Open struct for dynamic objects - Quiz 11easy Metaprogramming Fundamentals - Send for calling methods dynamically - Quiz 1easy Metaprogramming Fundamentals - Why metaprogramming is powerful in Ruby - Quiz 4medium Metaprogramming Fundamentals - Method_missing for catch-all - Quiz 1easy Regular Expressions - Common patterns and character classes - Quiz 1easy Regular Expressions - Gsub with regex - Quiz 7medium Regular Expressions - Match method and MatchData - Quiz 9hard Regular Expressions - Gsub with regex - Quiz 3easy Regular Expressions - Why regex is powerful in Ruby - Quiz 5medium