Convert multi dimentional array to array of hashes

  • Follow


Hi,

How can I turn and array like this this

[[1,2,3,4,5],[1,2,3,4,5]]

into this

[{:lt=>1,:ln=>1},{:lt=>2,:ln=>2},{:lt=>3,:ln=>3},{:lt=>4,:ln=>4},{:lt=>5,:ln=>5}]

Cheers
-- 
Posted via http://www.ruby-forum.com/.

0
Reply All4miller 4/7/2010 9:24:29 AM

You can try something like that :

a = [[1,2,3,4,5],[1,2,3,4,5]]
a.transpose.collect {|e| {:lt => e.first, :ln => e.last} }

Aurélien AMILIN


Le 07/04/2010 11:24, All4miller All4miller a écrit :
> Hi,
>
> How can I turn and array like this this
>
> [[1,2,3,4,5],[1,2,3,4,5]]
>
> into this
>
> [{:lt=>1,:ln=>1},{:lt=>2,:ln=>2},{:lt=>3,:ln=>3},{:lt=>4,:ln=>4},{:lt=>5,:ln=>5}]
>
> Cheers
>   

0
Reply UTF 4/7/2010 9:38:12 AM


thanks that worked great
-- 
Posted via http://www.ruby-forum.com/.

0
Reply all4 4/7/2010 9:56:49 AM

2 Replies
448 Views

(page loaded in 0.454 seconds)

Similiar Articles:













7/21/2012 4:01:36 AM


Reply: