On 26 Apr 2008, at 09:17, rushnosh wrote:
>
> a = [ [ ''john'' , ''195'' ] , [
''jack'' , ''132'' ] ]
>
> i need to convert this to:
>
> b = [ [ ''name'' , ''john'' ] , [
''id'' , ''195'' ] , [ ''name2''
, ''jack'' ] ,
> [ ''id2'' , ''132'' ] ]
>
a.inject([]) {| total , pair| total << [''name'',
pair.first] << [''id'',
pair.last] }
Fred> i am throwing a blank
>
> b = Array.new
> a.each do_with_index do | new, index |
> b << [ ''name#{index}'', new[0] ]
> b << [ ''id#{index}'', new[1] ]
> end
>
> does this make sense, can''t this be done with 1 line ?
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---