diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-05-07 12:31:20 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-05-07 12:31:20 -0700 |
commit | 3a82ff9555adc59e62cf8cebdc90ccad8b26b297 (patch) | |
tree | 03e34adb1e3c33fb1640a9b802c0058c686396ee | |
parent | 7ec3f33e3a5aa6d561ce34ae36c3beb495a0b6c7 (diff) | |
parent | 3880ab0d7ca8d38c870279a1ad3495fba1c2995a (diff) | |
download | rails-3a82ff9555adc59e62cf8cebdc90ccad8b26b297.tar.gz rails-3a82ff9555adc59e62cf8cebdc90ccad8b26b297.tar.bz2 rails-3a82ff9555adc59e62cf8cebdc90ccad8b26b297.zip |
Merge pull request #438 from jasonmichaelroth/ordinalize_negative_numbers
ordinalize negative numbers patch
-rw-r--r-- | activesupport/lib/active_support/inflector/methods.rb | 4 | ||||
-rw-r--r-- | activesupport/test/inflector_test_cases.rb | 30 |
2 files changed, 32 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index de49750083..dd2beef89d 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -136,10 +136,10 @@ module ActiveSupport # ordinalize(1002) # => "1002nd" # ordinalize(1003) # => "1003rd" def ordinalize(number) - if (11..13).include?(number.to_i % 100) + if (11..13).include?(number.to_i.abs % 100) "#{number}th" else - case number.to_i % 10 + case number.to_i.abs % 10 when 1; "#{number}st" when 2; "#{number}nd" when 3; "#{number}rd" diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb index 2b144e5931..ec9d92794c 100644 --- a/activesupport/test/inflector_test_cases.rb +++ b/activesupport/test/inflector_test_cases.rb @@ -215,6 +215,36 @@ module InflectorTestCases } OrdinalNumbers = { + "-1" => "-1st", + "-2" => "-2nd", + "-3" => "-3rd", + "-4" => "-4th", + "-5" => "-5th", + "-6" => "-6th", + "-7" => "-7th", + "-8" => "-8th", + "-9" => "-9th", + "-10" => "-10th", + "-11" => "-11th", + "-12" => "-12th", + "-13" => "-13th", + "-14" => "-14th", + "-20" => "-20th", + "-21" => "-21st", + "-22" => "-22nd", + "-23" => "-23rd", + "-24" => "-24th", + "-100" => "-100th", + "-101" => "-101st", + "-102" => "-102nd", + "-103" => "-103rd", + "-104" => "-104th", + "-110" => "-110th", + "-111" => "-111th", + "-112" => "-112th", + "-113" => "-113th", + "-1000" => "-1000th", + "-1001" => "-1001st", "0" => "0th", "1" => "1st", "2" => "2nd", |