Skip to content
This repository
Browse code

Added support for pluralization with a different starting letter than…

… the singular version (cow/kine) (closes #4929) [norri_b/hasmanyjosh]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7092 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 46b0e7d1d77c77d013235e3bf99d1afb89513cc9 1 parent 73fba4f
David Heinemeier Hansson authored June 23, 2007
2  activesupport/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* Added support for pluralization with a different starting letter than the singular version (cow/kine) #4929 [norri_b/hasmanyjosh]
  4
+
3 5
 * Demote Hash#to_xml to use XmlSimple#xml_in_string so it can't read files or stdin.  #8453 [candlerb, Jeremy Kemper]
4 6
 
5 7
 * Backport clean_logger changes to support ruby 1.8.2 [mislav]
1  activesupport/lib/active_support/inflections.rb
@@ -47,6 +47,7 @@
47 47
   inflect.irregular('child', 'children')
48 48
   inflect.irregular('sex', 'sexes')
49 49
   inflect.irregular('move', 'moves')
  50
+  inflect.irregular('cow', 'kine')
50 51
 
51 52
   inflect.uncountable(%w(equipment information rice money species series fish sheep))
52 53
 end
11  activesupport/lib/active_support/inflector.rb
@@ -47,8 +47,15 @@ def singular(rule, replacement)
47 47
     #   irregular 'octopus', 'octopi'
48 48
     #   irregular 'person', 'people'
49 49
     def irregular(singular, plural)
50  
-      plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1])
51  
-      singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1])
  50
+      if singular[0,1].upcase == plural[0,1].upcase
  51
+        plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1])
  52
+        singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1])
  53
+      else
  54
+        plural(Regexp.new("#{singular[0,1].upcase}(?i)#{singular[1..-1]}$"), plural[0,1].upcase + plural[1..-1])
  55
+        plural(Regexp.new("#{singular[0,1].downcase}(?i)#{singular[1..-1]}$"), plural[0,1].downcase + plural[1..-1])
  56
+        singular(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), singular[0,1].upcase + singular[1..-1])
  57
+        singular(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), singular[0,1].downcase + singular[1..-1])       
  58
+      end
52 59
     end
53 60
 
54 61
     # Add uncountable words that shouldn't be attempted inflected.
4  activesupport/test/inflector_test.rb
@@ -104,7 +104,9 @@ class InflectorTest < Test::Unit::TestCase
104 104
 
105 105
     "horse"       => "horses",
106 106
     "prize"       => "prizes",
107  
-    "edge"        => "edges"
  107
+    "edge"        => "edges",
  108
+
  109
+    "cow"         => "kine"
108 110
   }
109 111
 
110 112
   CamelToUnderscore = {

0 notes on commit 46b0e7d

Please sign in to comment.
Something went wrong with that request. Please try again.