aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activesupport/lib/active_support/locale/en.rb21
1 files changed, 12 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/locale/en.rb b/activesupport/lib/active_support/locale/en.rb
index 26c2280c95..a2a7ea7ae1 100644
--- a/activesupport/lib/active_support/locale/en.rb
+++ b/activesupport/lib/active_support/locale/en.rb
@@ -5,16 +5,19 @@
number: {
nth: {
ordinals: lambda do |_key, number:, **_options|
- abs_number = number.to_i.abs
-
- if (11..13).cover?(abs_number % 100)
- "th"
+ case number
+ when 1; "st"
+ when 2; "nd"
+ when 3; "rd"
+ when 4, 5, 6, 7, 8, 9, 10, 11, 12, 13; "th"
else
- case abs_number % 10
- when 1 then "st"
- when 2 then "nd"
- when 3 then "rd"
- else "th"
+ num_modulo = number.to_i.abs % 100
+ num_modulo %= 10 if num_modulo > 13
+ case num_modulo
+ when 1; "st"
+ when 2; "nd"
+ when 3; "rd"
+ else "th"
end
end
end,