Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/workarea/ext/freedom_patches/money.rb,
lib/workarea/ext/freedom_patches/string.rb
Direct Known Subclasses
Instance Method Summary collapse
- #optionize(sep = '-') ⇒ Object (also: #slugify, #systemize)
Instance Method Details
#optionize(sep = '-') ⇒ Object Also known as: slugify, systemize
2 3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/workarea/ext/freedom_patches/string.rb', line 2 def optionize(sep = '-') result = downcase.strip # Turn unwanted chars into the separator result.gsub!(/[^a-z0-9\-_]+/, sep) re_sep = Regexp.escape(sep) # No more than one of the separator in a row. result.gsub!(/#{re_sep}{2,}/, sep) result.underscore end |