0

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]?

1 Answer 1

3

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])
Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.