Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/core_ext/string.rb
Constant Summary collapse
- DISALLOWED_CHARACTERS =
"[\-\s\.\,\?\'\"\:\;\\\/]"
Instance Method Summary collapse
Instance Method Details
#humanize ⇒ Object
4 5 6 |
# File 'lib/core_ext/string.rb', line 4 def humanize gsub(DISALLOWED_CHARACTERS, " ").split(" ").map(&:capitalize).join("") end |
#sanitize ⇒ Object
14 15 16 |
# File 'lib/core_ext/string.rb', line 14 def sanitize gsub(DISALLOWED_CHARACTERS, "_") end |
#underscore ⇒ Object
8 9 10 11 12 |
# File 'lib/core_ext/string.rb', line 8 def underscore u = "" sanitize.split("").each_with_index do |c, i|; if i > 0 && c == c.upcase; u += " "; end; u += c.downcase; end; u.gsub(" ", "_") end |