Permalink
Browse files

Better handle pluralizing uncountable words

  • Loading branch information...
1 parent 74478bd commit 33b18be4b1bd1d69887073fe46d6c3f882c7baff David Genord II committed Jun 11, 2010
Showing with 6 additions and 4 deletions.
  1. +6 −4 activesupport/lib/active_support/inflector/inflections.rb
@@ -129,12 +129,14 @@ def inflections
def pluralize(word)
result = word.to_s.dup
- if word.empty? || inflections.uncountables.include?(result.downcase)
- result
- else
+ if m = (/(.*_)([a-z]+)$/i.match(result) || /^([A-Za-z]+)([A-Z][a-z]+)$/.match(result))
+ result = m[2]
+ end
+
+ unless word.empty? || inflections.uncountables.include?(result.downcase)
inflections.plurals.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
- result
end
+ m ? (m[1] + result) : result
end
# The reverse of +pluralize+, returns the singular form of a word in a string.

0 comments on commit 33b18be

Please sign in to comment.