0

How can I pass a an array of strings as attributes when creating new instance of a class? Say I want to do something like this:

Person.new(person_attrs) #<= Wrong number of arguments. Expected 3, got 1

where person_attrs.inspect returns ['foo', 'bar', 'baz']

1 Answer 1

1

It's expecting a hash when setting the attributes to an object. You are getting the Wrong number of arguments. Expected 3, got 1 error because it thinks the array as a whole is one argument (it does not care about it's contents).

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.