Permalink
Browse files

New inflectors will overwrite defaults [#337 state:resolved]

Signed-off-by: Tarmo Tänav <tarmo@itech.ee>
  • Loading branch information...
1 parent 74c3c70 commit a652c300ac9d60f6420d1cf86632f6a3c4ceef17 @wagenet wagenet committed with tarmo Aug 23, 2008
Showing with 13 additions and 0 deletions.
  1. +6 −0 activesupport/lib/active_support/inflector.rb
  2. +7 −0 activesupport/test/inflector_test.rb
@@ -39,12 +39,16 @@ def initialize
# 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 @@ def singular(rule, replacement)
# 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])
@@ -34,6 +34,13 @@ def test_pluralize_empty_string
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))

0 comments on commit a652c30

Please sign in to comment.