Bird
0
0

What will be the output of this Ruby code if the gem 'colorize' is installed?

medium📝 Predict Output Q4 of 15
Ruby - Gems and Bundler
What will be the output of this Ruby code if the gem 'colorize' is installed?
require 'colorize'
puts 'Hello'.colorize(:red)
ASyntax error due to wrong method
BPlain text 'Hello' without color
CRuntime error: gem not found
DHello printed in red color in the terminal
Step-by-Step Solution
Solution:
  1. Step 1: Understand the 'colorize' gem usage

    The 'colorize' gem adds color methods to strings, so 'Hello'.colorize(:red) prints red text.
  2. Step 2: Confirm gem is installed and code runs

    Since the gem is installed and required, the output will be 'Hello' in red color in the terminal.
  3. Final Answer:

    Hello printed in red color in the terminal -> Option D
  4. Quick Check:

    colorize gem output = colored text [OK]
Quick Trick: Require gem first, then use its methods for expected output [OK]
Common Mistakes:
  • Assuming colorize changes text without requiring gem
  • Expecting plain text output despite gem usage
  • Confusing method names causing syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes