Bird
0
0

Identify the error in this Ruby method definition:

medium📝 Debug Q14 of 15
Ruby - Methods
Identify the error in this Ruby method definition:
def save?
  # saves the object
  puts "Saving..."
  true
end

What is wrong with this method name?
AMethod name cannot contain ?
BMethod should end with ! instead of ?
CMethod ends with ? but performs an action, not a boolean check
DNo error, method is correct
Step-by-Step Solution
Solution:
  1. Step 1: Understand the meaning of ? suffix

    Methods ending with ? should return true or false and not perform side effects like saving.
  2. Step 2: Analyze the method behavior

    This method prints "Saving..." which is a side effect, so it should not end with ?.
  3. Final Answer:

    Method ends with ? but performs an action, not a boolean check -> Option C
  4. Quick Check:

    Methods with ? should not have side effects [OK]
Quick Trick: ? means boolean check, not side effects [OK]
Common Mistakes:
MISTAKES
  • Using ? for methods that change state
  • Ignoring method side effects
  • Confusing ! and ? suffix meanings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes