Reputation: 1413
I have two arrays extracted from a HTML page:
@row_left = ['Title:', 'Author:', 'Price:', 'Description:', 'Seller:']
@row_right = ['The Well-Grounded Rubyist', 'David A. Black', '$34.99', 'A great book for Rubyists', 'Ruby Scholar']
How can I combine both arrays into a hash?
{
"Title:" => "The Well-Grounded Rubyist",
"Author:" => "David A. Black",
"Price:" => "$34.99",
"Description:" => "A great book for Rubyists",
"Seller:" => "Ruby Scholar"
}
Upvotes: 0
Views: 173
Reputation: 1810
If you are looking for merging two equal length arrays into a hash, I would do this:
a = [1,3,5]; b=[2,4,6]
Hash[a.zip(b)]
Upvotes: 3