Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] Inconsistent behavior in pluralizing uncountable words

#4836

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

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

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Paul Barry
    Paul Barry
    • 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.

    June 12th, 2010 @ 01:33 AM

  2. David Genord II
    David Genord II

    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.

    June 12th, 2010 @ 04:53 AM

  3. Santiago Pastorino
    Santiago Pastorino
    • 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.

    February 2nd, 2011 @ 04:37 PM

  4. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:37 PM