Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Duane Johnson http://blog.inquirylabs.com/

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

String#to_id

Convert any (English) text to a programming-language friendly identifier.

class String
  def to_id
    downcase.gsub(/\W+/, ' ').strip.gsub(' ', '_')
  end
 
  def to_id!
    replace to_id
  end
end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS