Hi, I have two arrays: A = ["a", "b", "c", "d", ...] B = ["1", "2", "3", "4", ...] And I need to create new array C C = ["a$1", "b$2", "c$3", "d$4", ...] How so I do this in ruby way? Thanks, --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jan 16, 12:48 pm, kimda <ki...-yOgK34DqlZDxlngV0+vsch2eb7JE58TQ@public.gmane.org> wrote:> Hi, > > I have two arrays: > > A = ["a", "b", "c", "d", ...] > B = ["1", "2", "3", "4", ...] > > And I need to create new array C > > C = ["a$1", "b$2", "c$3", "d$4", ...] > > How so I do this in ruby way? > > Thanks,http://www.ruby-doc.org/core/classes/Array.html#M002221 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jan 16, 2008, at 3:48 PM, kimda wrote:> Hi, > > I have two arrays: > > A = ["a", "b", "c", "d", ...] > B = ["1", "2", "3", "4", ...] > > And I need to create new array C > > C = ["a$1", "b$2", "c$3", "d$4", ...] > > How so I do this in ruby way? > > Thanks,irb> A = (''a''..''e'').to_a; B = (1..5).to_a; C = A.zip(B).map {|(a,b)| "#{a}$#{b}"} => ["a$1", "b$2", "c$3", "d$4", "e$5"] But you shouldn''t use Capitals unless you intend to create a constant. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Check out the ruby docs for arrays and try it itself. Sent from my iPhone On Jan 16, 2008, at 12:48 PM, kimda <kimda-yOgK34DqlZDxlngV0+vsch2eb7JE58TQ@public.gmane.org> wrote:> > Hi, > > I have two arrays: > > A = ["a", "b", "c", "d", ...] > B = ["1", "2", "3", "4", ...] > > And I need to create new array C > > C = ["a$1", "b$2", "c$3", "d$4", ...] > > How so I do this in ruby way? > > Thanks, > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
thank you so much!! On Jan 16, 4:24 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> On Jan 16, 2008, at 3:48 PM, kimda wrote: > > > Hi, > > > I have two arrays: > > > A = ["a", "b", "c", "d", ...] > > B = ["1", "2", "3", "4", ...] > > > And I need to create new array C > > > C = ["a$1", "b$2", "c$3", "d$4", ...] > > > How so I do this in ruby way? > > > Thanks, > > irb> A = (''a''..''e'').to_a; B = (1..5).to_a; C = A.zip(B).map {|(a,b)| > "#{a}$#{b}"} > => ["a$1", "b$2", "c$3", "d$4", "e$5"] > > But you shouldn''t use Capitals unless you intend to create a constant. > > -Rob > > Rob Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---