0
0
Rubyprogramming~15 mins

IRB customization in Ruby - Mini Project: Build & Apply

Choose your learning style9 modes available
IRB Customization
📖 Scenario: You often use IRB (Interactive Ruby) to test small Ruby code snippets quickly. Customizing IRB can make your work easier and more fun by adding colors, changing prompts, or loading helpful methods automatically.
🎯 Goal: You will create a simple IRB configuration file that changes the prompt and adds a helper method to greet the user.
📋 What You'll Learn
Create a Ruby hash called IRB.conf with a nested hash for :PROMPT containing a custom prompt named :MY_PROMPT
Set the :MY_PROMPT prompt to show "MyIRB> " as the prompt string
Add a helper method called greet that takes a name parameter and returns "Hello, <name>!"
Print the result of calling greet("Friend") to show the greeting
💡 Why This Matters
🌍 Real World
Customizing IRB helps Ruby developers work faster and more comfortably by tailoring the interactive console to their preferences.
💼 Career
Many Ruby developers customize IRB or similar REPLs to improve productivity, making this skill useful for software development roles.
Progress0 / 4 steps
1
Create the IRB prompt configuration
Create a Ruby hash called IRB.conf with a nested hash for :PROMPT containing a custom prompt named :MY_PROMPT that has a key :PROMPT_I set to the string "MyIRB> ".
Ruby
Need a hint?

Use a nested hash structure with keys :PROMPT and :MY_PROMPT. Set :PROMPT_I to "MyIRB> "

2
Add a helper method called greet
Define a method called greet that takes one parameter called name and returns the string "Hello, <name>!" where <name> is replaced by the parameter value.
Ruby
Need a hint?

Use string interpolation with #{name} inside double quotes to create the greeting.

3
Call the greet method with "Friend"
Call the method greet with the argument "Friend" and assign the result to a variable called message.
Ruby
Need a hint?

Assign the result of greet("Friend") to message.

4
Print the greeting message
Print the variable message to display the greeting.
Ruby
Need a hint?

Use puts message to print the greeting.