tags:

views:

46

answers:

1

I have array that element is hash

a = [{:history_date=>"15/07/10"}, {:open_price=>"7.90"}]

I want to convert to this

h = {:history_date=>"15/07/10", :open_price=>"7.90"}

someone please help me.

+4  A: 

How about:

h = a.inject(&:merge)

Each hash in the array is merged into the previous hash until we get down to one element. &:merge is shorthand for the following, which may be easier to understand, but is slightly longer:

h = a.inject { |all, element| all.merge(element) }
Matchu
Thank you very much
neokain
@neokain - glad to help :) I'm sure you know, but please remember to accept the answer once SO will let you :D
Matchu
Thank again :) you're my hero.
neokain