Bartek Iwaszkiewicz
2011-Apr-05 23:31 UTC
Problem with conversion array of strings to array of arrays of integers
Hi Is it possible to convert array like this ["0", "1", "2", "1,2", "3", "1,3", "1,2,3,4,5,6,9"] to this [[0], [1], [2], [1,2], [3], [1,3], [1,2,3,4,5,6,9]] (all should be int) Any help will be very appreciated couse I''ve really stucked with this. Thanks in advance, Bartek Iwaszkiewicz -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Kendall Gifford
2011-Apr-05 23:44 UTC
Re: Problem with conversion array of strings to array of arrays of integers
On Tuesday, April 5, 2011 5:31:16 PM UTC-6, rails.rookie wrote:> > Hi > > Is it possible to convert array like this ["0", "1", "2", "1,2", > "3", "1,3", "1,2,3,4,5,6,9"] > to this [[0], [1], [2], [1,2], [3], [1,3], [1,2,3,4,5,6,9]] (all should > be int) > > Any help will be very appreciated couse I''ve really stucked with this. > > Thanks in advance, > Bartek Iwaszkiewicz >x = ["0", "1", "2", "1,2", "3", "1,3", "1,2,3,4,5,6,9"] y = x.map { |z| z.split(",").map(&:to_i) } On Tuesday, April 5, 2011 5:31:16 PM UTC-6, rails.rookie wrote:> > Hi > > Is it possible to convert array like this ["0", "1", "2", "1,2", > "3", "1,3", "1,2,3,4,5,6,9"] > to this [[0], [1], [2], [1,2], [3], [1,3], [1,2,3,4,5,6,9]] (all should > be int) > > Any help will be very appreciated couse I''ve really stucked with this. > > Thanks in advance, > Bartek Iwaszkiewicz >["0", "1", "2", "1,2", "3", "1,3", "1,2,3,4,5,6,9"].map { |x| x.split(",").map(&:to_i) } -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Bartek Iwaszkiewicz
2011-Apr-06 00:09 UTC
Re: Re: Problem with conversion array of strings to array of arrays of integers
W dniu 2011-04-06 01:44, Kendall Gifford pisze:> .map { |x| x.split(",").map(&:to_i) }Thank you very much Kendall, it is exactly what i need. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.