Bird
0
0

Which statement about Ruby method definitions using def is TRUE?

hard📝 Conceptual Q10 of 15
Ruby - Methods
Which statement about Ruby method definitions using def is TRUE?
AMethods must always have parentheses around parameters
BMethods can return the last evaluated expression without an explicit return
CMethods cannot have optional parameters
DMethod names can include spaces if enclosed in quotes
Step-by-Step Solution
Solution:
  1. Step 1: Recall Ruby method syntax rules

    Parentheses around parameters are optional, so A is false.
  2. Step 2: Understand return behavior

    Ruby methods return the last evaluated expression automatically, so C is true.
  3. Step 3: Check optional parameters and naming

    Ruby supports optional parameters, so B is false. Method names cannot have spaces, so D is false.
  4. Final Answer:

    Methods can return the last evaluated expression without an explicit return -> Option B
  5. Quick Check:

    Implicit return is Ruby method feature [OK]
Quick Trick: Ruby methods return last expression automatically [OK]
Common Mistakes:
  • Thinking parentheses are mandatory
  • Believing explicit return is required
  • Assuming method names can have spaces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes