This project is archived and is in readonly mode.

#4836 ✓stale
David Genord II

[PATCH] Inconsistent behavior in pluralizing uncountable words

Reported by David Genord II | June 11th, 2010 @ 08:55 PM

I have noticed an inconsistent behavior in pluralizing uncountable words
"rice".pluralize => "rice" "WhiteRice".pluralize => "WhiteRices" "white_rice".pluralize => "white_rices"

I have attached a patch that corrects this behavior to give the expected results as follows
"rice".pluralize => "rice" "WhiteRice".pluralize => "WhiteRice" "white_rice".pluralize => "white_rice"

The commits can also be found at
http://github.com/xspond/rails/commit/33b18be4b1bd1d69887073fe46d6c...
http://github.com/xspond/rails/commit/d030faa81c35fc4c405ab79503958...

Comments and changes to this ticket

  • Paul Barry

    Paul Barry June 12th, 2010 @ 01:33 AM

    • Tag changed from activesupport, inflections to activesupport, inflections, patch

    This patch looks good. There's obviously a bug that the test shows which is that existing compound word string, so a word like WhiteRice, is incorrectly pluralized to WhiteRices.

    I've attached an updated patch that refactors the implementation of pluralize to make it a little clear what's happening, IMHO. Rather than grok the regexps to try to infer the intent, I think it's clearer to just underscore the word and check to see if the last word is in the list of uncountables. It's not obivous what m = (/(.*_)([a-z]+)$/i.match(result) || /^([A-Za-z]+)([A-Z][a-z]+)$/.match(result)) means at a glance.

  • David Genord II

    David Genord II June 12th, 2010 @ 04:53 AM

    While I agree that your code is cleaner to read .underscore is a very expensive method to run in comparison to 2 regular expressions. Considering that pluralize is a heavily used inflection I believe the performance hit is a heavy price in comparison to a comment explaining the regular expressions.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:37 PM

    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:37 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Referenced by

Pages