Method: ActiveSupport::Inflector#singularize

Defined in:
activesupport/lib/active_support/inflector/methods.rb

#singularize(word, locale = :en) ⇒ Object

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

If passed an optional locale parameter, the word will be singularized using rules defined for that language. By default, this parameter is set to :en.

singularize('posts')            # => "post"
singularize('octopi')           # => "octopus"
singularize('sheep')            # => "sheep"
singularize('word')             # => "word"
singularize('CamelOctopi')      # => "CamelOctopus"
singularize('leyes', :es)       # => "ley"
[View source]

48
49
50
# File 'activesupport/lib/active_support/inflector/methods.rb', line 48

def singularize(word, locale = :en)
  apply_inflections(word, inflections(locale).singulars, locale)
end