Bird
0
0

Why does this code raise an error?

medium📝 Debug Q7 of 15
Ruby - Functional Patterns in Ruby
Why does this code raise an error?
nil.strip.upcase
ABecause strip returns nil
BBecause upcase cannot be called on strings
CBecause nil does not have the method strip
DBecause method chaining is not allowed on nil
Step-by-Step Solution
Solution:
  1. Step 1: Check methods on nil

    nil is an object but does not have the strip method.
  2. Step 2: Understand error cause

    Calling strip on nil causes NoMethodError, so chaining fails immediately.
  3. Final Answer:

    Because nil does not have the method strip -> Option C
  4. Quick Check:

    Calling method on nil without definition causes error [OK]
Quick Trick: Check if object supports method before chaining [OK]
Common Mistakes:
  • Thinking upcase is the problem
  • Assuming strip returns nil
  • Believing chaining is disallowed on nil

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes