Bird
0
0

Which of the following correctly defines a Ruby method that accepts any number of arguments?

easy📝 Syntax Q3 of 15
Ruby - Methods
Which of the following correctly defines a Ruby method that accepts any number of arguments?
Adef example(*params); end
Bdef example(params*); end
Cdef example(&params); end
Ddef example(params...); end
Step-by-Step Solution
Solution:
  1. Step 1: Understand Ruby syntax for variable arguments

    Ruby uses an asterisk (*) before a parameter name to accept variable-length arguments.
  2. Step 2: Analyze each option

    def example(*params); end uses *params correctly. Options B, C, and D use invalid syntax.
  3. Final Answer:

    def example(*params); end -> Option A
  4. Quick Check:

    Check for asterisk before parameter name [OK]
Quick Trick: Use * before parameter to accept variable args [OK]
Common Mistakes:
  • Using & instead of * for variable arguments
  • Placing * after parameter name
  • Using ... which is invalid in Ruby

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes