mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Refactor Inflector#ordinal to avoid converting the number twice
This commit is contained in:
parent
5cdeb5ef7d
commit
ade6c74ba6
1 changed files with 4 additions and 2 deletions
|
@ -286,10 +286,12 @@ module ActiveSupport
|
|||
# ordinal(-11) # => "th"
|
||||
# ordinal(-1021) # => "st"
|
||||
def ordinal(number)
|
||||
if (11..13).include?(number.to_i.abs % 100)
|
||||
abs_number = number.to_i.abs
|
||||
|
||||
if (11..13).include?(abs_number % 100)
|
||||
"th"
|
||||
else
|
||||
case number.to_i.abs % 10
|
||||
case abs_number % 10
|
||||
when 1; "st"
|
||||
when 2; "nd"
|
||||
when 3; "rd"
|
||||
|
|
Loading…
Reference in a new issue