diff options
author | Peter Wagenet <peter.wagenet@gmail.com> | 2008-08-23 13:33:07 -0400 |
---|---|---|
committer | Tarmo Tänav <tarmo@itech.ee> | 2008-08-23 20:43:22 +0300 |
commit | a652c300ac9d60f6420d1cf86632f6a3c4ceef17 (patch) | |
tree | 939e62d3d9b79feb62a1032a3a6748b80684798f | |
parent | 74c3c701f73407a5bb1a11be2b5b221fe39895d3 (diff) | |
download | rails-a652c300ac9d60f6420d1cf86632f6a3c4ceef17.tar.gz rails-a652c300ac9d60f6420d1cf86632f6a3c4ceef17.tar.bz2 rails-a652c300ac9d60f6420d1cf86632f6a3c4ceef17.zip |
New inflectors will overwrite defaults [#337 state:resolved]
Signed-off-by: Tarmo Tänav <tarmo@itech.ee>
-rw-r--r-- | activesupport/lib/active_support/inflector.rb | 6 | ||||
-rw-r--r-- | activesupport/test/inflector_test.rb | 7 |
2 files changed, 13 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb index 1e189465bd..f2ca94115e 100644 --- a/activesupport/lib/active_support/inflector.rb +++ b/activesupport/lib/active_support/inflector.rb @@ -39,12 +39,16 @@ module ActiveSupport # Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression. # The replacement should always be a string that may include references to the matched data from the rule. def plural(rule, replacement) + @uncountables.delete(rule) if rule.is_a?(String) + @uncountables.delete(replacement) @plurals.insert(0, [rule, replacement]) end # Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression. # The replacement should always be a string that may include references to the matched data from the rule. def singular(rule, replacement) + @uncountables.delete(rule) if rule.is_a?(String) + @uncountables.delete(replacement) @singulars.insert(0, [rule, replacement]) end @@ -55,6 +59,8 @@ module ActiveSupport # irregular 'octopus', 'octopi' # irregular 'person', 'people' def irregular(singular, plural) + @uncountables.delete(singular) + @uncountables.delete(plural) 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]) diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index b2fad4a9bc..8eebe1be25 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -34,6 +34,13 @@ class InflectorTest < Test::Unit::TestCase end end + def test_overwrite_previous_inflectors + assert_equal("series", ActiveSupport::Inflector.singularize("series")) + ActiveSupport::Inflector.inflections.singular "series", "serie" + assert_equal("serie", ActiveSupport::Inflector.singularize("series")) + ActiveSupport::Inflector.inflections.uncountable "series" # Return to normal + end + MixtureToTitleCase.each do |before, titleized| define_method "test_titleize_#{before}" do assert_equal(titleized, ActiveSupport::Inflector.titleize(before)) |