Bird
0
0

Find the error in this Ruby predicate method:

medium📝 Debug Q6 of 15
Ruby - Methods
Find the error in this Ruby predicate method:
def adult?(age)
  if age >= 18
    true
  else
    false
AMethod name should not have '?'
BComparison operator is incorrect
CMissing 'end' keyword to close method
DReturn values should be strings
Step-by-Step Solution
Solution:
  1. Step 1: Check method structure

    Every method definition must end with an 'end' keyword.
  2. Step 2: Identify missing 'end'

    The method has an if-else block but lacks the final 'end' to close the method.
  3. Final Answer:

    Missing 'end' keyword to close method -> Option C
  4. Quick Check:

    Method definitions require 'end' [OK]
Quick Trick: Always close methods with 'end' keyword [OK]
Common Mistakes:
  • Forgetting 'end' for method or blocks
  • Misusing '?' in method name
  • Wrong comparison operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes