# Conditional pluralize without the number

**URL:** <https://www.ruby-forum.com/t/conditional-pluralize-without-the-number/82779>\
**Category:** Rails\
**Created:** [January 20, 2007, 8:22pm UTC](https://www.ruby-forum.com/t/conditional-pluralize-without-the-number/82779 "2007-01-20T20:22:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adambeazley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@adambeazley](https://www.ruby-forum.com/u/adambeazley)\
**Post date:** [January 20, 2007, 8:22pm UTC](https://www.ruby-forum.com/t/conditional-pluralize-without-the-number/82779/1 "2007-01-20T20:22:29Z")

</div>

Hi.

Assume you have an array of person names. I want to generate results in  
my view that look like this:

Abby is your friend

or

Abby, Bob, and Carol are your friends.

So I’d like to say:

```
<%= friends.to_sentence %>
<%= pluralize(friends.count, "is") %>
your <%= pluralize(friends.count, "friend") %>

```

But because pluralize puts in the number, I get:

Abby 1 is your 1 friend

or

Abby, Bob, and Carol 3 are your 3 friends.

Is there a way around this? The API only shows the one form for  
pluralize.

Thanks!

/afb

---

<div class="post-metadata">

**Author:** ![adambeazley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@adambeazley](https://www.ruby-forum.com/u/adambeazley)\
**Post date:** [January 20, 2007, 8:48pm UTC](https://www.ruby-forum.com/t/conditional-pluralize-without-the-number/82779/2 "2007-01-20T20:48:22Z")

</div>

Perhaps this helps:

[http://api.rubyonrails.org/classes/Inflector.html#M001076](http://api.rubyonrails.org/classes/Inflector.html#M001076)

Kind of strange, though. The Sting::Inflections simply do a  
Inflection.pluralize(word), and that method seems to return the word  
only (the method I’m talking about is the one in the link above).  
Weird.

On Jan 20, 8:22 pm, Adam B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![adambeazley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@adambeazley](https://www.ruby-forum.com/u/adambeazley)\
**Post date:** [January 20, 2007, 9:26pm UTC](https://www.ruby-forum.com/t/conditional-pluralize-without-the-number/82779/3 "2007-01-20T21:26:28Z")

</div>

You’ll need to use to\_sentence to make a custom helper, in  
application\_helper.rb:

def friends\_list\_to\_sentence(friends)  
if friends.to\_a.count == 1  
friends + " is your friend."  
else  
friends.to\_sentence + " are your friends."  
end  
end

That’s quick and dirty and I didn’t test it.

On 1/20/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Jan 20, 8:22 pm, Adam B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> > Abby, Bob, and Carol are your friends.
> > 
> > –  
> > Posted viahttp://www.ruby-forum.com/.
> 
> >

## – Jim

Jim L.  
removed\_email\_address@domain.invalid
