I'm fairly a beginner in Ruby and I'm trying to do the following: Let's say I have two arrays:
array_1 = ["NY", "SF", "NL", "SY"]
array_2 = ["apple", "banana"]
I want to merge the arrays to a hash so each object in array_1 will be assigned with the objects in array_2
Thanks in advance.
x = [:foo, :bar, :baz]
y = [1, 2, 3]
x.zip(y).to_h # => {:foo=>1, :bar=>2, :baz=>3}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With