From 091965c0fc7384c17cce9e71a80f515b1139d460 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 29 Apr 2009 23:12:34 -0700 Subject: Prefer behavior check to RUBY_VERSION to catch 1.8 backports --- activesupport/lib/active_support/core_ext/integer/even_odd.rb | 4 ++-- activesupport/lib/active_support/core_ext/string/conversions.rb | 2 +- activesupport/lib/active_support/core_ext/time/conversions.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/integer/even_odd.rb b/activesupport/lib/active_support/core_ext/integer/even_odd.rb index 6d005268a3..8f9a97b44c 100644 --- a/activesupport/lib/active_support/core_ext/integer/even_odd.rb +++ b/activesupport/lib/active_support/core_ext/integer/even_odd.rb @@ -7,10 +7,10 @@ class Integer # Is the integer a multiple of 2? def even? multiple_of? 2 - end if RUBY_VERSION < '1.9' + end unless method_defined?(:even?) # Is the integer not a multiple of 2? def odd? !even? - end if RUBY_VERSION < '1.9' + end unless method_defined?(:odd?) end diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index 3f05db62c3..2b9f8c70f6 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -5,7 +5,7 @@ class String # 'a'.ord == 'a'[0] for Ruby 1.9 forward compatibility. def ord self[0] - end if RUBY_VERSION < '1.9' + end unless method_defined?(:ord) # Form can be either :utc (default) or :local. def to_time(form = :utc) diff --git a/activesupport/lib/active_support/core_ext/time/conversions.rb b/activesupport/lib/active_support/core_ext/time/conversions.rb index 18261e139f..94e01597a9 100644 --- a/activesupport/lib/active_support/core_ext/time/conversions.rb +++ b/activesupport/lib/active_support/core_ext/time/conversions.rb @@ -63,7 +63,7 @@ class Time # your_time.to_date # => Tue, 13 Jan 2009 def to_date ::Date.new(year, month, day) - end + end unless method_defined?(:to_date) # A method to keep Time, Date and DateTime instances interchangeable on conversions. # In this case, it simply returns +self+. @@ -80,5 +80,5 @@ class Time # your_time.to_datetime # => Tue, 13 Jan 2009 13:13:03 -0500 def to_datetime ::DateTime.civil(year, month, day, hour, min, sec, Rational(utc_offset, 86400)) - end + end unless method_defined?(:to_datetime) end -- cgit v1.2.3