Bird
0
0

Find the problem in this Ruby code:

medium📝 Debug Q7 of 15
Ruby - String Operations
Find the problem in this Ruby code:
text = "abc abc abc"
result = text.gsub('abc')
puts result
AVariable result is not assigned properly
Bgsub cannot be called on strings
CNo problem, code runs fine
Dgsub method missing replacement argument
Step-by-Step Solution
Solution:
  1. Step 1: Review gsub method usage

    gsub requires two arguments: pattern and replacement string.
  2. Step 2: Identify missing replacement argument

    The code only passes the pattern 'abc', missing the replacement string.
  3. Final Answer:

    gsub method missing replacement argument -> Option D
  4. Quick Check:

    gsub needs two arguments = C [OK]
Quick Trick: gsub needs pattern and replacement arguments [OK]
Common Mistakes:
  • Calling gsub with only one argument
  • Assuming gsub modifies string in place
  • Confusing gsub with methods that accept one argument

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes