I have a ruby function with the following function header def get_value( default, *args ), and I'm using recursion in my function body, and I want to pass the args array without the first element, what I have used is get_value(default, args.slice(1, args.length)), however, after using a debugger, I found that the args in the recursed function was an array of arrays, and the inner arrays contained my elements. So if my main array was [:files, :mode] the recursed array would be [[:mode]]. How can I make it that is becomes [:mode]?
Add a comment
|
1 Answer
Call get_value with the splat operator:
get_value(default, *args.slice(1, args.length))
or with additional brevity
get_value(default, *args[1..-1])
1 Comment
ichigolas
That's another question => endofline.wordpress.com/2011/01/21/the-strange-ruby-splat