Skip to content

Instantly share code, notes, and snippets.

@schovi
Created June 14, 2011 20:35
Show Gist options
  • 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