From: Josh Cheek Date: 2009-10-01T23:00:13+09:00 Subject: Re: Group by unique entries of a hash --000e0cd11362d204ee0474e01065 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Oct 1, 2009 at 8:15 AM, Ne Scripter wrote: > I am having real problems with my array. As expected my array contents > is like so: > > "00000004 00000005" > "00000003 00000006" > "00000001" > "00000002" > > I now want 6 indivdual elements insteal of 4. I have tried to split the > double entries up with split, however they remain together. Is there > something fundamental I am missing? I want an array like so > > array = ["00000004", "00000005", "00000003", "00000006", "00000001", > "00000002"] > > Sorry if this is simple, I have spent several hours chopping and > changing. > > Thanks > > S > > David A. Black wrote: > > On Thu, 1 Oct 2009, Simon Krahnke wrote: > > > >> or > >> > >> hash, ocrID, *ignored = *data.split(",") > >> > >> if you want to ignore everything behind a second comma, or > >> > >> hash, ocrID = *data.split(",", 2) > >> > >> if you want to include a second comma and everything behind it into the > >> ocrID string. > > > > I don't think you need the * for any of them. This: > > > > hash, ocrID = data.split(',') > > > > should be fine for getting the first two values. > > > > > > David > > -- > Posted via http://www.ruby-forum.com/. > > x = [ "00000004 00000005" , "00000003 00000006" , "00000001" , "00000002" , ] x.map!{|str| str.split(/\s+/) }.flatten! x # => ["00000004", "00000005", "00000003", "00000006", "00000001", "00000002"] --000e0cd11362d204ee0474e01065--