Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/support/string.rb

Instance Method Summary collapse

Instance Method Details

#pluralizeObject



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

#underscoreObject



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