Top Level Namespace

Defined Under Namespace

Classes: Entity, Tables, Ymldot

Constant Summary collapse

@@singular =

by activesupport/lib/active_support/inflector.rb

[]

Instance Method Summary collapse

Instance Method Details

#add_singular(rule, replace) ⇒ Object



5
6
7
# File 'lib/util.rb', line 5

def add_singular(rule, replace)
  @@singular << [rule, replace]
end

#singularize(word) ⇒ Object

The reverse of pluralize, returns the singular form of a word in a string.

Examples:

"posts".singularize            # => "post"
"octopi".singularize           # => "octopus"
"sheep".singluarize            # => "sheep"
"word".singluarize             # => "word"
"the blue mailmen".singularize # => "the blue mailman"
"CamelOctopi".singularize      # => "CamelOctopus"


43
44
45
46
47
# File 'lib/util.rb', line 43

def singularize(word)
  result = word.to_s.dup
  @@singular.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
  result
end