From 19ae8fc5e9e16519879236062a7c48370f00b9de Mon Sep 17 00:00:00 2001 From: Chris Gaffney Date: Thu, 18 Sep 2008 18:05:41 -0400 Subject: [PATCH] Ruby 1.9 compat: Add ord to Integer. --- .../lib/active_support/core_ext/integer.rb | 2 ++ .../active_support/core_ext/integer/conversions.rb | 13 +++++++++++++ activesupport/test/core_ext/integer_ext_test.rb | 4 ++++ 3 files changed, 19 insertions(+), 0 deletions(-) create mode 100644 activesupport/lib/active_support/core_ext/integer/conversions.rb diff --git a/activesupport/lib/active_support/core_ext/integer.rb b/activesupport/lib/active_support/core_ext/integer.rb index d1e6d76..9506ba8 100644 --- a/activesupport/lib/active_support/core_ext/integer.rb +++ b/activesupport/lib/active_support/core_ext/integer.rb @@ -1,7 +1,9 @@ require 'active_support/core_ext/integer/even_odd' require 'active_support/core_ext/integer/inflections' +require 'active_support/core_ext/integer/conversions' class Integer #:nodoc: include ActiveSupport::CoreExtensions::Integer::EvenOdd include ActiveSupport::CoreExtensions::Integer::Inflections + include ActiveSupport::CoreExtensions::Integer::Conversions end diff --git a/activesupport/lib/active_support/core_ext/integer/conversions.rb b/activesupport/lib/active_support/core_ext/integer/conversions.rb new file mode 100644 index 0000000..5aa7c9b --- /dev/null +++ b/activesupport/lib/active_support/core_ext/integer/conversions.rb @@ -0,0 +1,13 @@ +module ActiveSupport #:nodoc: + module CoreExtensions #:nodoc: + module Integer #:nodoc: + # Converting integers + module Conversions + # 1.ord == 1 for Ruby 1.9 forward compatibility. + def ord + self + end if RUBY_VERSION < '1.8.7' + end + end + end +end diff --git a/activesupport/test/core_ext/integer_ext_test.rb b/activesupport/test/core_ext/integer_ext_test.rb index 5ab3622..cb5ca16 100644 --- a/activesupport/test/core_ext/integer_ext_test.rb +++ b/activesupport/test/core_ext/integer_ext_test.rb @@ -34,4 +34,8 @@ class IntegerExtTest < Test::Unit::TestCase assert_equal '8th', 8.ordinalize 1000000000000000000000000000000000000000000000000000000000000000000000.ordinalize end + + def test_ord + assert_equal 1, 1.ord + end end -- 1.6.0.1