Bird
0
0

Which Ruby string method removes spaces only from the beginning and end of a string?

easy📝 Conceptual Q2 of 15
Ruby - String Operations
Which Ruby string method removes spaces only from the beginning and end of a string?
Aupcase
Bstrip
Cdowncase
Dchomp
Step-by-Step Solution
Solution:
  1. Step 1: Identify the purpose of strip

    The strip method removes whitespace characters from both the start and end of a string.
  2. Step 2: Differentiate from other methods

    upcase and downcase change letter cases, while chomp removes newline characters, not spaces.
  3. Final Answer:

    strip -> Option B
  4. Quick Check:

    strip = Remove spaces at ends [OK]
Quick Trick: strip trims spaces from start and end only [OK]
Common Mistakes:
MISTAKES
  • Confusing strip with chomp
  • Thinking upcase removes spaces
  • Assuming downcase trims spaces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes