Bird
0
0

You want to create a Ruby script that uses the 'colorize' gem to print text in red. Which sequence of steps is correct?

hard📝 Application Q15 of 15
Ruby - Gems and Bundler
You want to create a Ruby script that uses the 'colorize' gem to print text in red. Which sequence of steps is correct?
ARun <code>require 'colorize'</code>, then <code>gem install colorize</code>, then use <code>puts 'text'.colorize(:red)</code>
BRun <code>gem install colorize</code>, then <code>require 'colorize'</code>, then use <code>puts 'text'.colorize(:red)</code>
CUse <code>puts 'text'.colorize(:red)</code> directly without installing or requiring
DRun <code>gem add colorize</code>, then <code>require 'colorize'</code>, then use <code>puts 'text'.colorize(:red)</code>
Step-by-Step Solution
Solution:
  1. Step 1: Install the gem first

    You must install the gem using gem install colorize before using it.
  2. Step 2: Require the gem in your script

    Use require 'colorize' to load the gem's code.
  3. Step 3: Use the gem's method to color text

    Call puts 'text'.colorize(:red) to print red text.
  4. Final Answer:

    Run gem install, then require, then use colorize method -> Option B
  5. Quick Check:

    Install -> require -> use gem [OK]
Quick Trick: Install gem before require and usage [OK]
Common Mistakes:
  • Requiring gem before installing
  • Using 'gem add' instead of 'gem install'
  • Trying to use gem methods without require

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes