Bird
0
0

Which of the following is the correct syntax to remove spaces from the start and end of a string str in Ruby?

easy📝 Syntax Q12 of 15
Ruby - String Operations
Which of the following is the correct syntax to remove spaces from the start and end of a string str in Ruby?
Astr.strip()
Bstr.upcase()
Cstrip(str)
Dstr.trim()
Step-by-Step Solution
Solution:
  1. Step 1: Identify the method to remove spaces

    The Ruby method to remove spaces at start and end is strip, called on the string object.
  2. Step 2: Check correct method call syntax

    In Ruby, methods are called with dot notation: str.strip(). There is no trim method in Ruby.
  3. Final Answer:

    str.strip() -> Option A
  4. Quick Check:

    strip method called with dot = str.strip() [OK]
Quick Trick: Use dot notation: string.strip() removes spaces [OK]
Common Mistakes:
  • Using strip as a standalone function
  • Using trim instead of strip
  • Calling upcase to remove spaces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes