EastsideDev
EastsideDev

Reputation: 6639

Calling a method with keywords arguments

Ruby 2.6.3
Rails 5.2

def test_method(param1:, param2:, param3:)
end

test_method(param1: "food")

It is giving me the following error message:

Traceback (most recent call last):
        2: from (irb):11
        1: from (irb):8:in `test_method'
ArgumentError (missing keywords: param2, param3)

I thought the point of using method parameters, is for me to be able to specify the params I want to use, when calling this method. What am I missing? I am using this in a Rails 5.2 application, if that makes a difference.

Upvotes: 0

Views: 618

Answers (1)

arieljuod
arieljuod

Reputation: 15838

There are requried keyword arguments (use something:) and optional keyword arguments (use something: default_value). I think required keyword parameters should go before optional ones.

Upvotes: 1

Related Questions