Bird
0
0

What does the operator do when used with strings in Ruby?

easy📝 Conceptual Q1 of 15
Ruby - String Operations
What does the << operator do when used with strings in Ruby?
AIt appends the right string to the left string, modifying the original string.
BIt creates a new string by adding two strings without changing the originals.
CIt compares two strings for equality.
DIt removes the last character from the string.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the << operator

    The << operator appends the right string to the left string and changes the original string.
  2. Step 2: Compare with other string operations

    Unlike +, which creates a new string, << modifies the original string in place.
  3. Final Answer:

    It appends the right string to the left string, modifying the original string. -> Option A
  4. Quick Check:

    String concatenation with << = modifies original string [OK]
Quick Trick: Use << to add without making a new string [OK]
Common Mistakes:
MISTAKES
  • Thinking << creates a new string
  • Confusing << with +
  • Assuming << compares strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes