Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Nov 6, 2011
Merged

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

merged 1 commit into from Nov 6, 2011

Conversation

pksunkara
Copy link
Contributor

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 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inflectionize? :P apply_inflections?

sarahhodne added a commit to sarahhodne/rails that referenced this pull request Nov 6, 2011
@sarahhodne
Copy link
Contributor

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

@josevalim
Copy link
Contributor

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

@pksunkara
Copy link
Contributor Author

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

Test case coming through.

@josevalim
Copy link
Contributor

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

@pksunkara
Copy link
Contributor Author

Done. Please merge.

josevalim added a commit that referenced this pull request Nov 6, 2011
Make pluralize follow singularize's logic of uncountability check
@josevalim josevalim merged commit 6950639 into rails:master Nov 6, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants