Home > Net >  how to pass a variable to *args function parameter
how to pass a variable to *args function parameter

Time:02-02

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)

CodePudding user response:

Use * to expand the array.

str.start_with?(*list_of_strs)
  •  Tags:  
  • Related