0
0
Rubyprogramming~15 mins

Gem installation with gem install in Ruby - Mini Project: Build & Apply

Choose your learning style9 modes available
Gem installation with gem install
📖 Scenario: You want to use a Ruby gem to add extra features to your Ruby programs. Gems are like apps you can add to Ruby to do new things easily.Before using a gem, you need to install it on your computer using the gem install command.
🎯 Goal: Learn how to install a Ruby gem called colorize using the gem install command and verify it works by writing a simple Ruby script that uses it.
📋 What You'll Learn
Use the gem install colorize command to install the gem
Create a Ruby script that uses the colorize gem
Print colored text using the gem
Run the script to see the colored output
💡 Why This Matters
🌍 Real World
Installing gems lets you add ready-made tools to your Ruby projects, saving time and adding powerful features.
💼 Career
Knowing how to install and use gems is essential for Ruby developers to build modern applications efficiently.
Progress0 / 4 steps
1
Create a Ruby script file
Create a Ruby file called color_test.rb and write this line at the top: require 'colorize'
Ruby
Need a hint?

The require line loads the gem so you can use it in your script.

2
Add a text variable
Add a variable called text and set it to the string 'Hello, Ruby!'
Ruby
Need a hint?

Variables hold information you want to use later in your program.

3
Use the gem to color the text
Use the colorize gem to make text appear in red color by calling text.colorize(:red) and save it in a variable called colored_text
Ruby
Need a hint?

The colorize method changes the text color. Use :red to make it red.

4
Print the colored text
Print the variable colored_text using puts to see the red colored text in the terminal
Ruby
Need a hint?

Use puts to show the colored text on the screen.