Skip to content

Instantly share code, notes, and snippets.

@schovi
Created June 14, 2011 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schovi/1025808 to your computer and use it in GitHub Desktop.
Save schovi/1025808 to your computer and use it in GitHub Desktop.
Ruby 1.9.x String#to_slug
module String
def to_slug
value = self.mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/n, '').to_s
value.gsub!(/[']+/, '')
value.gsub!(/\W+/, ' ')
value.strip!
value.downcase!
value.gsub!(' ', '-')
value
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment