Bird
0
0

Which of the following is a valid way to call a method defined as def example(*args)?

easy📝 Conceptual Q2 of 15
Ruby - Methods
Which of the following is a valid way to call a method defined as def example(*args)?
Aexample(1, 2, 3)
BAll of the above
Cexample('a', 'b')
Dexample()
Step-by-Step Solution
Solution:
  1. Step 1: Understand method calls with variable arguments

    A method defined with *args can be called with zero or more arguments.
  2. Step 2: Check each option

    A passes three arguments, D passes none, and C passes two. All are valid calls.
  3. Final Answer:

    All of the above -> Option B
  4. Quick Check:

    Method with *args accepts any number of arguments [OK]
Quick Trick: You can call *args methods with any number of arguments [OK]
Common Mistakes:
  • Thinking method must have at least one argument
  • Believing empty call is invalid
  • Confusing *args with fixed parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes