Bird
0
0

Identify the error in this Ruby code snippet:

medium📝 Debug Q6 of 15
Ruby - String Operations
Identify the error in this Ruby code snippet:
text = "hello world"
text.sub('world')
AMissing replacement argument for sub method
BIncorrect method name, should be gsub
CString variable not defined
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check sub method arguments

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

    The code only provides the pattern 'world', missing the replacement argument.
  3. Final Answer:

    Missing replacement argument for sub method -> Option A
  4. Quick Check:

    sub needs two arguments = B [OK]
Quick Trick: Always provide pattern and replacement to sub [OK]
Common Mistakes:
  • Forgetting the replacement argument
  • Assuming sub works with one argument
  • Confusing sub with methods that accept one argument

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes