Skip to content

Instantly share code, notes, and snippets.

@rubypanther
Created October 27, 2011 23:59
Show Gist options
  • Save rubypanther/1321247 to your computer and use it in GitHub Desktop.
Save rubypanther/1321247 to your computer and use it in GitHub Desktop.
Sort an array of strings by their first word and then their first number
%w/ foo11 foo2 3foo foo4 bar2 foo1 bar99-a /.sort do |a,b|
[a[/[[:alpha:]]+/],a[/[[:digit:]]+/]] <=>
[b[/[[:alpha:]]+/],b[/[[:digit:]]+/]]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment