This post originated from an RSS feed registered with Ruby Buzz
by Jay Fields.
Original Post: String#singularize
Feed Title: Jay Fields Thoughts
Feed URL: http://blog.jayfields.com/rss.xml
Feed Description: Thoughts on Software Development
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"
Usage I generally use singularize when metaprogrammming to convert from a potentially plural version of a class name to something that I know can be constantized.