Sending elements of an array as arguments to a method call

Posted by Bryce on Stack Overflow See other posts from Stack Overflow or by Bryce
Published on 2010-12-29T08:24:48Z Indexed on 2010/12/29 8:53 UTC
Read the original article Hit count: 325

Filed under:
|

I have a method that accepts the splat operator:

def hello(foo, *bar)   
   #... do some stuff 
end

I have an array with a variable length that I'd like to send into this hello method:

arr1 = ['baz', 'stuff']
arr2 = ['ding', 'dong', 'dang']

I'd like to call the method with arr1 and arr2 as arguments to that method but I keep getting hung up in that *bar is being interpreted as an array instead of individual arguments. To make things more fun, I can't change the hello method at all.

I'm looking for something similar to this SO question but in ruby.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby