Recall & Review
beginner
What are keyword arguments in Ruby?
Keyword arguments are a way to pass arguments to a method by explicitly naming them, making the code easier to read and arguments easier to manage.
Click to reveal answer
beginner
How do you define a method with keyword arguments in Ruby?
You define keyword arguments by listing them with colons in the method parameters, like
def greet(name:, age:).Click to reveal answer
intermediate
What happens if you call a method with keyword arguments but omit one required keyword?
Ruby raises an ArgumentError because the method expects all required keyword arguments to be provided.
Click to reveal answer
intermediate
How can you provide default values for keyword arguments in Ruby?
You assign a default value in the method definition like
def greet(name:, age: 18). If the caller omits age, it uses 18.Click to reveal answer
beginner
What is the benefit of using keyword arguments over positional arguments?
Keyword arguments improve code readability and reduce errors by clearly naming each argument, so the order does not matter.
Click to reveal answer
How do you call a Ruby method
def order(item:, quantity:) with keyword arguments?✗ Incorrect
Keyword arguments are passed by naming them with colons, like
item: 'apple'.What error occurs if a required keyword argument is missing when calling a method?
✗ Incorrect
Ruby raises an ArgumentError if a required keyword argument is not provided.
How do you set a default value for a keyword argument in Ruby?
✗ Incorrect
Default values for keyword arguments are set with
arg: 5 in the method definition.Which is a benefit of keyword arguments?
✗ Incorrect
Keyword arguments let you pass arguments in any order by naming them explicitly.
What is the correct way to define a method with two required keyword arguments
name and age?✗ Incorrect
Keyword arguments are defined with colons after the names:
name:, age:.Explain how keyword arguments improve method calls in Ruby.
Think about how naming each argument helps when calling methods.
You got /4 concepts.
Describe how to define keyword arguments with default values and what happens if you omit them when calling the method.
Look at how to assign values in the method definition.
You got /4 concepts.