Bird
0
0

Which of the following is the correct syntax to append " world" to the string variable greeting using in Ruby?

easy📝 Syntax Q12 of 15
Ruby - String Operations
Which of the following is the correct syntax to append " world" to the string variable greeting using << in Ruby?
Agreeting.add(" world")
Bgreeting + " world"
Cgreeting.append(" world")
Dgreeting << " world"
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct operator for appending

    In Ruby, << is used to append text to an existing string variable.
  2. Step 2: Check syntax correctness

    greeting << " world" correctly appends " world" to greeting. Other options are either invalid methods or use + which does not modify in place.
  3. Final Answer:

    greeting << " world" -> Option D
  4. Quick Check:

    Use << to append text in place [OK]
Quick Trick: Use << to add text directly to string [OK]
Common Mistakes:
  • Using + which creates a new string
  • Trying to use non-existent methods like add
  • Confusing method names like append which is not standard

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes