Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Make pluralize follow singularize's logic of uncountability check #3536

merged 1 commit into from

3 participants


I have added a test case which fails prior to the patch. All the tests pass including the new one now.

@@ -23,7 +23,7 @@ module ActiveSupport
def pluralize(word)
result = word.to_s.dup
- if word.empty? || inflections.uncountables.include?(result.downcase)
+ if word.empty? || inflections.uncountables.any? { |inflection| result =~ /\b#{inflection}\Z/i }
@josevalim Owner

Thanks for the pull request. Shouldn't we move this logic to a private method and have both pluralize and singularize calling it?

That would be DRYer. To me the two methods look almost exactly the same, except for the word.empty? part, so maybe we could extract most of the method into a private method and redefine pluralize to this:

def pluralize(word)
  somethingize(word, inflections.plurals)
  # Alternatively:
  somethingize(word, :plurals) # (and just do inflections.send(:plurals) in somethingize)
@josevalim Owner

Agreed with somethingize(word, inflections.plurals). The word.empty? check could exist in both methods, it is just a very simple optimization.

We would need a better name than somethingize though. Any suggestions?

@josevalim Owner

inflectionize? :P apply_inflections?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@henrikhodne henrikhodne referenced this pull request from a commit in henrikhodne/rails
@henrikhodne henrikhodne Refactored pluralize and singularize into a common method.
See diff discussion on rails/#3536.

I added the change in pluralize to my commit in #3537, but the test change should maybe still be added?


Yes, could you please rebase that pull request or send a new one with the test only? Thanks a lot!


Damn! I wanted to have a commit in rails. It would inspire me to contribute more.

Test case coming through.


@pkumar you still can! I am waiting on the test :)


Done. Please merge.

@josevalim josevalim merged commit 6950639 into rails:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 6, 2011
  1. @pksunkara
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 0 deletions.
  1. +1 −0  activesupport/test/inflector_test_cases.rb
1  activesupport/test/inflector_test_cases.rb
@@ -14,6 +14,7 @@ module InflectorTestCases
"fish" => "fish",
"jeans" => "jeans",
"funky jeans" => "funky jeans",
+ "my money" => "my money",
"category" => "categories",
"query" => "queries",
Something went wrong with that request. Please try again.