Bird
0
0

Which of these method calls correctly uses keyword arguments for the method def order(item:, quantity:)?

easy📝 Syntax Q3 of 15
Ruby - Methods
Which of these method calls correctly uses keyword arguments for the method def order(item:, quantity:)?
Aorder(item: 'apple', quantity: 3)
Border('apple', 3)
Corder(item = 'apple', quantity = 3)
Dorder(:item, :quantity)
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to call methods with keyword arguments

    Keyword arguments require naming the parameters with colons in the call.
  2. Step 2: Evaluate each call

    order(item: 'apple', quantity: 3) correctly names arguments with colons. order('apple', 3) uses positional arguments. order(item = 'apple', quantity = 3) uses assignment syntax incorrectly. order(:item, :quantity) passes symbols, not values.
  3. Final Answer:

    order(item: 'apple', quantity: 3) -> Option A
  4. Quick Check:

    Calling with keyword arguments = name: value pairs [OK]
Quick Trick: Call keyword args with name: value pairs [OK]
Common Mistakes:
MISTAKES
  • Passing arguments positionally to keyword parameters
  • Using equals (=) instead of colon (:) in calls
  • Passing symbols instead of values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes