Bird
0
0

What is the main difference between + and when used with strings in Ruby?

easy📝 Conceptual Q11 of 15
Ruby - String Operations
What is the main difference between + and << when used with strings in Ruby?
A<code>+</code> creates a new string, <code><<</code> modifies the original string.
B<code>+</code> modifies the original string, <code><<</code> creates a new string.
CBoth <code>+</code> and <code><<</code> create new strings without modifying the original.
DBoth <code>+</code> and <code><<</code> modify the original string in place.
Step-by-Step Solution
Solution:
  1. Step 1: Understand + behavior

    The + operator joins two strings but returns a new string without changing the original.
  2. Step 2: Understand << behavior

    The << operator appends text directly to the original string, modifying it in place.
  3. Final Answer:

    + creates a new string, << modifies the original string. -> Option A
  4. Quick Check:

    + new string, << modifies original [OK]
Quick Trick: Remember: + new string, << changes original [OK]
Common Mistakes:
  • Thinking + changes the original string
  • Confusing << with creating a new string
  • Assuming both operators behave the same

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes