Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/support/string.rb
Instance Method Summary collapse
Instance Method Details
#pluralize ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/support/string.rb', line 6 def pluralize if end_with?("y") && !%w[a e i o u].include?(self[-2].downcase) "#{self[0..-2]}ies" elsif end_with?("s", "sh", "ch", "x", "z") "#{self}es" else "#{self}s" end end |
#underscore ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/support/string.rb', line 18 def underscore word = gsub("::", "/") word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2') word.gsub!(/([a-z\d])([A-Z])/, '\1_\2') word.tr!("-", "_") word.downcase end |