Bird
0
0

What is wrong with this guard clause?

medium📝 Debug Q7 of 15
Ruby - Control Flow
What is wrong with this guard clause?
def valid?(input)
  return true if input.empty?
  false
end
AThe method should raise an error instead of returning
BMissing parentheses in method definition
CGuard clause should return false, not true
DIt returns true for empty input, which may be incorrect logic
Step-by-Step Solution
Solution:
  1. Step 1: Analyze guard clause logic

    The guard clause returns true if input is empty, which may not be the intended validation.
  2. Step 2: Consider typical validation meaning

    Usually, empty input is invalid, so returning true here is likely a logic mistake.
  3. Final Answer:

    It returns true for empty input, which may be incorrect logic -> Option D
  4. Quick Check:

    Guard clause logic must match validation intent [OK]
Quick Trick: Check guard clause logic matches expected validation [OK]
Common Mistakes:
  • Assuming empty input is valid
  • Ignoring method parentheses
  • Confusing return values with errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes