The reverse of pluralize, returns the singular form of a word in a string.Usage
Examples
- "posts".singularize #=> "post"
- "octopi".singularize #=> "octopus"
- "sheep".singluarize #=> "sheep"
- "word".singluarize #=> "word"
- "the blue mailmen".singularize #=> "the blue mailman"
- "CamelOctopi".singularize #=> "CamelOctopus"
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.
Test
unit_tests do
test "change plural word to singular word" do
assert_equal "class_name", "class_names".singularize
end
end
what's the point of these posts?
ReplyDeletehttp://blog.jayfields.com/2007/11/30-days-of-activesupport.html
ReplyDelete