(identity 'myron)

Tue, 27 Sep 2005

Ruby On Rails and Plurals [/programming]

I've been learning Ruby on Rails lately which is quite clean and elegant, but that's not what this post is about. From the moment I found out it attempts to auto-pluralize object names, I've been itching to bang on it to see what it understands and what it doesn't. The only thing I've heard said about it is that it's smart enough to understand child and children, person and people.... Well then, punk, let's go for a ride around the mess that is the English language, shall we?

% rails plurals
[a bunch of output about creating files and directories]
% cd plurals
% ruby script/generate model Child
[...]
    create  test/fixtures/children.yml

Works as advertised. Let's move on.

% ruby script/generate model Spy
[...]
    create  test/fixtures/spies.yml

Not bad, but still only smart enough to earn a preschool star sticker. What if my app's all about the world of fantasy fiction?

% ruby script/generate model Elf
[...]
    create  test/fixtures/elves.yml

Ok I'm mildly impressed at this poi—oh who am I kidding—it's time to bring out the big guns!

% ruby script/generate model Torpedo
[...]
    create  test/fixtures/torpedos.yml

Wrong! But most people won't even notice. Let's try something similar but more obviously wrong.

% ruby script/generate model Hero
[...]
    create  test/fixtures/heros.yml

Hehe. Now for nouns that have no plural forms at all.

% ruby script/generate model Deer
[...]
    create  test/fixtures/deers.yml
% ruby script/generate model Sheep
[...]
    create  test/fixtures/sheeps.yml

And finally the test for some Italian:

% ruby script/generate model Concerto
[...]
    create  test/fixtures/concertos.yml

For the record, this was done in Rails 0.13.1. Some other interesting examples it got right: Octopus/Octopi, Symposium/Symposia, and Vortex/Vortices. Oddly enough for each one of those, I could find a noun in the same "class" it would get wrong. It pluralized Fungus instead of Fungi, Ovums instead of Ova, Appendixes instead of Appendices. So go figure.

// posted at 19:58. permalink   comments

divider symbol