aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-11-04 18:51:47 -0200
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-11-04 18:51:47 -0200
commitade6c74ba6b5f10a923cd42564adfeddecbc4364 (patch)
tree5783bc6c968eb31dc89a5b2208967cffcefcd776 /activesupport
parent5cdeb5ef7db1bab944ff0ee2d64c6c896758bac6 (diff)
downloadrails-ade6c74ba6b5f10a923cd42564adfeddecbc4364.tar.gz
rails-ade6c74ba6b5f10a923cd42564adfeddecbc4364.tar.bz2
rails-ade6c74ba6b5f10a923cd42564adfeddecbc4364.zip
Refactor Inflector#ordinal to avoid converting the number twice
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index 3910a2dc42..1eb2b4212b 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -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"