diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-06-23 16:47:47 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-06-23 16:47:47 +0000 |
commit | 46b0e7d1d77c77d013235e3bf99d1afb89513cc9 (patch) | |
tree | ec6e353610a5feb717e9e1639b914e1a548d1cca /activesupport | |
parent | 73fba4faf13394540489063247a887a0d396af2f (diff) | |
download | rails-46b0e7d1d77c77d013235e3bf99d1afb89513cc9.tar.gz rails-46b0e7d1d77c77d013235e3bf99d1afb89513cc9.tar.bz2 rails-46b0e7d1d77c77d013235e3bf99d1afb89513cc9.zip |
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
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/inflections.rb | 1 | ||||
-rw-r--r-- | activesupport/lib/active_support/inflector.rb | 11 | ||||
-rw-r--r-- | activesupport/test/inflector_test.rb | 4 |
4 files changed, 15 insertions, 3 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index a4046061aa..be7eba5b0c 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added support for pluralization with a different starting letter than the singular version (cow/kine) #4929 [norri_b/hasmanyjosh] + * Demote Hash#to_xml to use XmlSimple#xml_in_string so it can't read files or stdin. #8453 [candlerb, Jeremy Kemper] * Backport clean_logger changes to support ruby 1.8.2 [mislav] diff --git a/activesupport/lib/active_support/inflections.rb b/activesupport/lib/active_support/inflections.rb index f53ef53ca4..967722c2bf 100644 --- a/activesupport/lib/active_support/inflections.rb +++ b/activesupport/lib/active_support/inflections.rb @@ -47,6 +47,7 @@ Inflector.inflections do |inflect| inflect.irregular('child', 'children') inflect.irregular('sex', 'sexes') inflect.irregular('move', 'moves') + inflect.irregular('cow', 'kine') inflect.uncountable(%w(equipment information rice money species series fish sheep)) end diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb index 084c58d389..db6e44e91b 100644 --- a/activesupport/lib/active_support/inflector.rb +++ b/activesupport/lib/active_support/inflector.rb @@ -47,8 +47,15 @@ module Inflector # irregular 'octopus', 'octopi' # irregular 'person', 'people' def irregular(singular, plural) - plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1]) - singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1]) + if singular[0,1].upcase == plural[0,1].upcase + plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1]) + singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1]) + else + plural(Regexp.new("#{singular[0,1].upcase}(?i)#{singular[1..-1]}$"), plural[0,1].upcase + plural[1..-1]) + plural(Regexp.new("#{singular[0,1].downcase}(?i)#{singular[1..-1]}$"), plural[0,1].downcase + plural[1..-1]) + singular(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), singular[0,1].upcase + singular[1..-1]) + singular(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), singular[0,1].downcase + singular[1..-1]) + end end # Add uncountable words that shouldn't be attempted inflected. diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 9849e0b52b..684150a925 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -104,7 +104,9 @@ class InflectorTest < Test::Unit::TestCase "horse" => "horses", "prize" => "prizes", - "edge" => "edges" + "edge" => "edges", + + "cow" => "kine" } CamelToUnderscore = { |