class String
Constants
- DISALLOWED_CHARACTERS
Public Instance Methods
humanize()
click to toggle source
# File lib/core_ext/string.rb, line 4 def humanize gsub(DISALLOWED_CHARACTERS, " ").split(" ").map(&:capitalize).join("") end
sanitize()
click to toggle source
# File lib/core_ext/string.rb, line 30 def sanitize gsub(/_{2,}/, "_").gsub(DISALLOWED_CHARACTERS, "_") end
underscore()
click to toggle source
# File lib/core_ext/string.rb, line 8 def underscore u = "" chars = sanitize.split("") unless chars.count == 0 while chars.first.match(DISALLOWED_CHARACTERS) chars.delete_at(0) end while chars.last.match(DISALLOWED_CHARACTERS) chars.delete_at(chars.count - 1) end end chars.each_with_index do |c, i| if c.match(/[A-Za-z]/) && i > 0 && c == c.upcase u += " " end u += c.downcase end u.gsub(/\s/, "_") end