Skip to content

Instantly share code, notes, and snippets.

@inky
Created July 5, 2014 17:28
Show Gist options
  • Save inky/d299cd26d7c3d51d47b5 to your computer and use it in GitHub Desktop.
Save inky/d299cd26d7c3d51d47b5 to your computer and use it in GitHub Desktop.
def make_slug(text)
text.downcase.split.map{ |w| w.delete '^a-z0-9' }.reject(&:empty?).join('-')
end
@johnholdun
Copy link

I've never seen it done like this before! I usually use a couple regexpeses like this:

text.downcase.gsub(/[^a-z0-9]+/, '-').gsub(/^-|-$/, '')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment