0

I have an array of data and an array of keys that are in a specific order:

original_data = ['hello', 'world', 'one', 'two']
keys = [:greeting, :location, :first, :second]

I would like to map the keys to the data to be able to reference each datum by a key like this.

data[:greeting].should == original_data[0]

How can I achieve this?

1 Answer 1

1

That would be:

data = Hash[keys.zip original_data]
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.