From: "David A. Black" Date: 2009-10-01T23:05:44+09:00 Subject: Re: Group by unique entries of a hash Hi -- On Thu, 1 Oct 2009, Josh Cheek wrote: > 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. >> > > x = [ > "00000004 00000005" , > "00000003 00000006" , > "00000001" , > "00000002" , > ] > > x.map!{|str| str.split(/\s+/) }.flatten! > > x # => ["00000004", "00000005", "00000003", "00000006", "00000001", > "00000002"] You can even dispense with the argument to split if it's just whitespace. Another option, though perhaps a slightly memory-wasting one: x.join(' ').split David -- David A. Black, Director Ruby Power and Light, LLC (http://www.rubypal.com) Ruby/Rails training, consulting, mentoring, code review Book: The Well-Grounded Rubyist (http://www.manning.com/black2)