public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
New inflectors will overwrite defaults [#337 state:resolved]

Signed-off-by: Tarmo Tänav <tarmo@itech.ee>
rxcfc (author)
Sat Aug 23 10:33:07 -0700 2008
Tarmo Tänav (committer)
Sat Aug 23 10:43:22 -0700 2008
commit  a652c300ac9d60f6420d1cf86632f6a3c4ceef17
tree    939e62d3d9b79feb62a1032a3a6748b80684798f
parent  74c3c701f73407a5bb1a11be2b5b221fe39895d3
...
39
40
41
 
 
42
43
44
45
46
47
 
 
48
49
50
...
55
56
57
 
 
58
59
60
...
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
...
59
60
61
62
63
64
65
66
0
@@ -39,12 +39,16 @@ module ActiveSupport
0
       # Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
0
       # The replacement should always be a string that may include references to the matched data from the rule.
0
       def plural(rule, replacement)
0
+        @uncountables.delete(rule) if rule.is_a?(String)
0
+        @uncountables.delete(replacement)
0
         @plurals.insert(0, [rule, replacement])
0
       end
0
 
0
       # Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
0
       # The replacement should always be a string that may include references to the matched data from the rule.
0
       def singular(rule, replacement)
0
+        @uncountables.delete(rule) if rule.is_a?(String)
0
+        @uncountables.delete(replacement)
0
         @singulars.insert(0, [rule, replacement])
0
       end
0
 
0
@@ -55,6 +59,8 @@ module ActiveSupport
0
       #   irregular 'octopus', 'octopi'
0
       #   irregular 'person', 'people'
0
       def irregular(singular, plural)
0
+        @uncountables.delete(singular)
0
+        @uncountables.delete(plural)
0
         if singular[0,1].upcase == plural[0,1].upcase
0
           plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1])
0
           singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1])
...
34
35
36
 
 
 
 
 
 
 
37
38
39
...
34
35
36
37
38
39
40
41
42
43
44
45
46
0
@@ -34,6 +34,13 @@ class InflectorTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
+  def test_overwrite_previous_inflectors
0
+    assert_equal("series", ActiveSupport::Inflector.singularize("series"))
0
+    ActiveSupport::Inflector.inflections.singular "series", "serie"
0
+    assert_equal("serie", ActiveSupport::Inflector.singularize("series"))
0
+    ActiveSupport::Inflector.inflections.uncountable "series" # Return to normal
0
+  end
0
+
0
   MixtureToTitleCase.each do |before, titleized|
0
     define_method "test_titleize_#{before}" do
0
       assert_equal(titleized, ActiveSupport::Inflector.titleize(before))

Comments