Sunday, November 04, 2007
Rails: String#pluralize
Documentation
I generally use pluralize for creating nice messages for users. The pluralize method can also be helpful for metaprogramming when converting from a class name to a table name.
Test
Returns the plural form of the word in the string.Usage
Examples
- "post".pluralize #=> "posts"
- "octopus".pluralize #=> "octopi"
- "sheep".pluralize #=> "sheep"
- "words".pluralize #=> "words"
- "the blue mailman".pluralize #=> "the blue mailmen"
- "CamelOctopus".pluralize #=> "CamelOctopi"
I generally use pluralize for creating nice messages for users. The pluralize method can also be helpful for metaprogramming when converting from a class name to a table name.
Test
unit_tests do
test "change singular word to plural word" do
assert_equal "names", "name".pluralize
end
endLabels: activesupport, rails
Comments:
<< Home
"CamelOctopus".pluralize #=> "CamelOctopi"
Ugh ... it frustrates me that Rails codifies a grammatical error.
The plural of "octopus" is "octopodes" -- or "octopuses" if you wish to Anglicize it -- not "octopi".
Even though the word ends in -us, "pus" is a Greek root and not a Latin one, meaning "foot" -- witness "pedestrian" or "pedal".
Ugh ... it frustrates me that Rails codifies a grammatical error.
The plural of "octopus" is "octopodes" -- or "octopuses" if you wish to Anglicize it -- not "octopi".
Even though the word ends in -us, "pus" is a Greek root and not a Latin one, meaning "foot" -- witness "pedestrian" or "pedal".
And it also chokes on another common construct:
"attorney general".pluralize #=> "attorney generals"
It's actually "attorneys general".
That one is more easily understood -- it would be non-trivial to identify "attorney general" as a noun-adjective construct.
But actually specifying something incorrect, like "octopi"? Blech.
"attorney general".pluralize #=> "attorney generals"
It's actually "attorneys general".
That one is more easily understood -- it would be non-trivial to identify "attorney general" as a noun-adjective construct.
But actually specifying something incorrect, like "octopi"? Blech.
Not a problem, Joe. active_support lets one customize pluralization rules.
Inflector.inflections do |inflect|
inflect.irregular 'octopus', 'octopodes'
inflect.irregular 'attorney general', 'attorneys general'
end
Inflector.inflections do |inflect|
inflect.irregular 'octopus', 'octopodes'
inflect.irregular 'attorney general', 'attorneys general'
end
Brian:
Yeah, but the problem is that RoR ships with an error. The octopus/octopi thing appears six times in lib/active_support/inflector.rb as an example of the "right" way to do pluralization/singularization. :(
A nitpick, I know.
Yeah, but the problem is that RoR ships with an error. The octopus/octopi thing appears six times in lib/active_support/inflector.rb as an example of the "right" way to do pluralization/singularization. :(
A nitpick, I know.
http://www.reference.com/search?r=13&q=Octopodes
according to reference.com 3 forms are right : octopus = 'eight-legs', with plural forms: octopuses, octopi, or octopodes and reference.com uses octopuses as plural form in text.
just noticed...
Post a Comment
according to reference.com 3 forms are right : octopus = 'eight-legs', with plural forms: octopuses, octopi, or octopodes and reference.com uses octopuses as plural form in text.
just noticed...
<< Home


