From: Daniel Berger Date: 2005-12-22T06:17:49+09:00 Subject: Re: move to front of array Jacob Fugal wrote: > On 12/21/05, Payton Swick wrote: > > Hi, > > > > I have an array of Strings, and I'd like to find one of the items by > > Regexp, then move that item to the front of the array, eg: > > > > array = %w(a B c d Cool e f G) > > array.unshift(array.slice!(array.index(array.find { |i| i =~ /cool/i > > }))) if array.find { |i| i =~ /cool/i } > > > > Better/cleaner/shorter ways to do it? > > > > -Payton > > array = %w(a B c d Cool e f G) > if cool = array.find { |i| i =~ /cool/i } > array.delete(cool) > array.unshift(cool) > end array.unshift(array.delete("Cool")) Regards, Dan