From: Ezra Zygmuntowicz Date: 2005-12-22T06:13:11+09:00 Subject: Re: move to front of array On Dec 21, 2005, at 12:08 PM, 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.unshift(array.delete_at(array.index("Cool"))) # => ["Cool", "a", "B", "c", "d", "e", "f", "G"] -Ezra