From 6fa0190fe4c1bf9f8306198536306de883039a27 Mon Sep 17 00:00:00 2001 From: Tim Gildea Date: Thu, 14 Jul 2011 11:16:28 -0400 Subject: Add ActiveSupport::Inflector.ordinal and Integer#ordinal --- .../lib/active_support/core_ext/integer/inflections.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/integer/inflections.rb b/activesupport/lib/active_support/core_ext/integer/inflections.rb index 0e606056c0..1e30687166 100644 --- a/activesupport/lib/active_support/core_ext/integer/inflections.rb +++ b/activesupport/lib/active_support/core_ext/integer/inflections.rb @@ -14,4 +14,18 @@ class Integer def ordinalize ActiveSupport::Inflector.ordinalize(self) end + + # Ordinal returns the suffix used to denote the position + # in an ordered sequence such as 1st, 2nd, 3rd, 4th. + # + # 1.ordinal # => "st" + # 2.ordinal # => "nd" + # 1002.ordinal # => "nd" + # 1003.ordinal # => "rd" + # -11.ordinal # => "th" + # -1001.ordinal # => "st" + # + def ordinal + ActiveSupport::Inflector.ordinal(self) + end end -- cgit v1.2.3