Skip to content

Instantly share code, notes, and snippets.

@anewusername1
Created February 24, 2011 15:18
Show Gist options
  • Save anewusername1/842278 to your computer and use it in GitHub Desktop.
Save anewusername1/842278 to your computer and use it in GitHub Desktop.
Array sorting
class Array
def natural_sort
just_letters = self.select{|el| el =~ /^[a-zA-Z]+$/}
numbers = self - just_letters
just_letters.sort + numbers.sort{|x,y| x.gsub(/[a-zA-Z]+/, '').to_i <=> y.gsub(/[a-zA-Z]+/, '').to_i}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment