From: Eero Saynatkari Date: 2005-12-22T05:38:35+09:00 Subject: Re: move to front of array 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? This should work (but without error checking): array.unshift(array.delete(array.grep(/cool/i).first)) > -Payton E -- Posted via http://www.ruby-forum.com/.