# Pluralization

**URL:** <https://www.ruby-forum.com/t/pluralization/95699>\
**Category:** Rails\
**Created:** [December 7, 2005, 8:40am UTC](https://www.ruby-forum.com/t/pluralization/95699 "2005-12-07T08:40:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![winescout](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/4af34b/32.png) [@winescout](https://www.ruby-forum.com/u/winescout)\
**Post date:** [December 7, 2005, 8:40am UTC](https://www.ruby-forum.com/t/pluralization/95699/1 "2005-12-07T08:40:59Z")

</div>

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  
play  
with it yourself, gem install localization, and you’ll get it. There’s  
some  
other cool stuff in there too!

Anyhow, I’m a bit stuck, or braindead. (actually both tonight) and could  
use  
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  
method to  
convert from singular to plural, and back again, but as far as I can  
tell,  
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’  
require ‘linguistics’  
Linguistics::use( :en)

class LinguisticsTest \< Test::Unit::TestCase  
def test\_conversion  
assert\_equal(“mice”,“mouse”.en.plural)  
end

def test\_converting\_plural\_word  
assert\_equal(“mice”,“mice”.en.plural, “mice not recognized as  
plural”)  
end

def test\_converting\_plural\_word\_2  
assert\_equal(“cats”, “cats”.en.plural, “cats not recognized as  
plural”)  
end

#if there were a truth function, this would be it  
def test\_plural\_truth  
assert “cats”.en.plural?  
end  
end

============== RESULTS ==================

Loaded suite linguistics\_test  
Started  
.FFE  
Finished in 0.112234 seconds.

1. Failure:  
test\_converting\_plural\_word(LinguisticsTest) [linguistics\_test.rb:12]:  
mice not recognized as plural.  
\<“mice”\> expected but was  
\<“mices”\>.

2. Failure:  
test\_converting\_plural\_word\_2(LinguisticsTest) [linguistics\_test.rb:16]:  
cats not recognized as plural.  
\<“cats”\> expected but was  
\<“cat”\>.

3. Error:  
test\_plural\_truth(LinguisticsTest):  
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:in`method\_missing’  
linguistics\_test.rb:21:in `test\_plural\_truth’

4 tests, 3 assertions, 2 failures, 1 errors

---

<div class="post-metadata">

**Author:** ![winescout](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/4af34b/32.png) [@winescout](https://www.ruby-forum.com/u/winescout)\
**Post date:** [December 8, 2005, 6:29pm UTC](https://www.ruby-forum.com/t/pluralization/95699/2 "2005-12-08T18:29:54Z")

</div>

there is a plurization paper and Perl program at  
[Damian Conway's Online Papers](http://www.csse.monash.edu.au/~damian/papers/)  
(look for ‘English Plurals’ on the page).  
You may be able to steal\h\h\h\h\hrecycle the algorithm  
and make a ruby port.

matthew clark wrote:

> method to convert from singular to plural, and back again, but as far as  
> I can tell, no way just to test plurality.

[snip]

---

<div class="post-metadata">

**Author:** ![winescout](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/4af34b/32.png) [@winescout](https://www.ruby-forum.com/u/winescout)\
**Post date:** [December 8, 2005, 7:59pm UTC](https://www.ruby-forum.com/t/pluralization/95699/3 "2005-12-08T19:59:51Z")

</div>

Hi,

On 12/7/05, matthew clark [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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.

Not sure about the localization gem, but it’s pretty trivial using  
Active Support’s inflector:

class String  
def plural?  
self == self.pluralize  
end  
end

‘cow’.plural? # =\> false  
‘cows’.plural? # =\> true

–  
sam
