Bird
0
0

Identify the bug in this predicate method:

medium📝 Debug Q7 of 15
Ruby - Methods
Identify the bug in this predicate method:
def valid_name?(name)
  name.length > 0
  true
end
AThe method always returns true ignoring the condition
BMethod name should not end with '?'
CMissing parentheses in method definition
DComparison operator is wrong
Step-by-Step Solution
Solution:
  1. Step 1: Analyze method body

    The method evaluates name.length > 0 but then returns true unconditionally.
  2. Step 2: Understand return value

    Because true is the last line, the method always returns true, ignoring the condition.
  3. Final Answer:

    The method always returns true ignoring the condition -> Option A
  4. Quick Check:

    Last expression determines return value [OK]
Quick Trick: Return the condition directly for correct boolean result [OK]
Common Mistakes:
  • Adding extra true ignoring condition
  • Wrong method naming
  • Syntax errors from missing end

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes