Peabrain
Peabrain

Reputation: 589

how to pass a variable to *args function parameter

I have the following line of code:

str.start_with?("str1", "str2", "str3")

Is it possible I can pass a variable/list into this function instead? Something like:

list_of_strs = ["str1", "str2", "str3"]
str.start_with?(list_of_strs)

Upvotes: 0

Views: 51

Answers (1)

Chris
Chris

Reputation: 36451

Use * to expand the array.

str.start_with?(*list_of_strs)

Upvotes: 2

Related Questions