Bird
0
0

What is the output of this Ruby code?

medium📝 Predict Output Q4 of 15
Ruby - String Operations
What is the output of this Ruby code?
text = "  Ruby Rocks  "
puts text.strip.downcase
A"RUBY ROCKS"
B" ruby rocks "
C"ruby rocks"
D" RUBY ROCKS "
Step-by-Step Solution
Solution:
  1. Step 1: Apply strip method

    strip removes spaces from start and end, so " Ruby Rocks " becomes "Ruby Rocks".
  2. Step 2: Apply downcase method

    downcase converts all letters to lowercase, so "Ruby Rocks" becomes "ruby rocks".
  3. Final Answer:

    "ruby rocks" -> Option C
  4. Quick Check:

    strip + downcase = trimmed lowercase string [OK]
Quick Trick: strip removes spaces, downcase makes letters small [OK]
Common Mistakes:
MISTAKES
  • Ignoring strip effect
  • Using upcase instead of downcase
  • Expecting spaces to remain

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes