I got curious about Active Record playing tricks with pluralization, and
found a few places in my rig where it might be useful. If you want to
with it yourself, gem install localization, and you’ll get it. There’s
other cool stuff in there too!
Anyhow, I’m a bit stuck, or braindead. (actually both tonight) and could
some fresh ideas.
What I want to do is test a string to see if it is a plural, and if so
branch the code and do something else with it. Localization has a
convert from singular to plural, and back again, but as far as I can
no way just to test plurality. Can you think of a way to do this test?
Here are some tests that should make my meaning clear.
require File.dirname(FILE) + ‘/…/test_helper’
class LinguisticsTest < Test::Unit::TestCase
assert_equal(“mice”,“mice”.en.plural, “mice not recognized as
assert_equal(“cats”, “cats”.en.plural, “cats not recognized as
#if there were a truth function, this would be it
============== RESULTS ==================
Loaded suite linguistics_test
Finished in 0.112234 seconds.
mice not recognized as plural.
<“mice”> expected but was
cats not recognized as plural.
<“cats”> expected but was
NoMethodError: undefined method
plural?' for <English languageProxy for String object "cats">:#<Class:0xb7627b44> /usr/lib/ruby/gems/1.8/gems/Linguistics-1.0.3/lib/linguistics.rb:90:inmethod_missing’
4 tests, 3 assertions, 2 failures, 1 errors