1

I'm trying to pass a nest of parameters to a rails function defined as so...

def test(*params)
    stuff
end

If I pass the following

test :mark, :was, :here

or

test :mark, :was, :here=>:today

everything is fine. However, when I do this...

test :mark, :was=>:really, :here

An error is thrown. Any clues where I'm going wrong?

M.

1 Answer 1

1

If the last argument is a hash you don't have to use curly barces, but if the hash is not at the end of your list of arguments you do need the curly braces. In the middle Ruby doesn't know if the comma indicates the next argument or the next item in the hash. So you have to do this:

test :mark, {:was=>:really}, :here
Sign up to request clarification or add additional context in comments.

Comments

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.