Bird
0
0

Find the error in this Ruby code:

medium📝 Debug Q6 of 15
Ruby - String Operations
Find the error in this Ruby code:
str = " Hello "
puts str.strip.upcase()
Aupcase should be called before strip
BMissing parentheses in method calls
Cstrip method does not exist
DNo error, code runs correctly
Step-by-Step Solution
Solution:
  1. Step 1: Check method existence and syntax

    Both strip and upcase are valid Ruby string methods and can be chained.
  2. Step 2: Verify parentheses usage

    Parentheses are optional in Ruby method calls; upcase() is valid and strip without parentheses is also valid.
  3. Final Answer:

    No error, code runs correctly -> Option D
  4. Quick Check:

    strip and upcase chaining is valid [OK]
Quick Trick: Parentheses optional in Ruby method calls [OK]
Common Mistakes:
  • Thinking parentheses are mandatory
  • Assuming method order causes error
  • Believing strip is undefined

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes