instance method
singularize
Ruby on Rails 3.0.20
Since v2.2.3Signature
singularize(word)
The reverse of pluralize, returns the singular form of a word in a string.
Examples:
"posts".singularize # => "post" "octopi".singularize # => "octopus" "sheep".singularize # => "sheep" "word".singularize # => "word" "CamelOctopi".singularize # => "CamelOctopus"
Parameters
-
wordreq
Source
# File activesupport/lib/active_support/inflector/inflections.rb, line 148
def singularize(word)
result = word.to_s.dup
if inflections.uncountables.any? { |inflection| result =~ /\b(#{inflection})\Z/i }
result
else
inflections.singulars.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
result
end
end
Defined in activesupport/lib/active_support/inflector/inflections.rb line 148
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::Inflector