Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Forked from robbyrussell/move-to-front-of-line.rb
Created February 27, 2009 00:30
Show Gist options
  • Save lukeredpath/71220 to your computer and use it in GitHub Desktop.
Save lukeredpath/71220 to your computer and use it in GitHub Desktop.
class Array
def move_to_front_of_line(x)
unshift(delete(self[x]))
end
end
>> people = [ 'Alex', 'Carlos', 'Dawn', 'Chris', 'Robby', 'Gary', 'Allison' ]
=> ["Alex", "Carlos", "Dawn", "Chris", "Robby", "Gary", "Allison"]
>>
?> people.move_to_front_of_line(3)
=> ["Chris", "Alex", "Carlos", "Dawn", "Robby", "Gary", "Allison"]
>>
?> people.move_to_front_of_line(people.index('Allison'))
=> ["Allison", "Alex", "Carlos", "Dawn", "Chris", "Robby", "Gary"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment