Bird
0
0

What will this Ruby code print?

medium📝 Predict Output Q5 of 15
Ruby - Enumerable and Collection Processing
What will this Ruby code print?
words = ['cat', 'dog', 'bird']
words.each { |w| puts w.upcase }
Acat dog bird
BError: undefined method upcase
CCat Dog Bird
DCAT DOG BIRD
Step-by-Step Solution
Solution:
  1. Step 1: Understand the each iteration and method call

    Each word is passed to the block, and upcase converts it to uppercase.
  2. Step 2: Determine the printed output

    All words will be printed in uppercase: CAT, DOG, BIRD.
  3. Final Answer:

    CAT DOG BIRD -> Option D
  4. Quick Check:

    each with upcase = uppercase words [OK]
Quick Trick: Use string methods inside each block to transform elements [OK]
Common Mistakes:
  • Printing original words
  • Capitalizing only first letter
  • Expecting error on upcase

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes