Forum: Ruby Problem with using active support core extensions in my own ruby programs

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jonathan G. (Guest)
on 2008-10-24 12:42
(Received via mailing list)
This code used to perform correctly with activesupport 2.0.2:

require 'rubygems'
require 'time'
require 'active_support'

class Time
  include ActiveSupport::CoreExtensions::Time::Calculations

nxt = => 7)
nxt = nxt.tomorrow if nxt <
puts nxt

However, with activesupport 2.1.2 it now fails:
'compare_without_coercion': stack level too deep (SystemStackError)
          from ./ '<'
          from ./

The above is obviously caused by the comparison:
if nxt <

Inside calculations.rb we seem to be getting lost in:
        # Layers additional behavior on Time#<=> so that DateTime and
  ActiveSupport::TimeWithZone instances
        # can be chronologically compared with a Time
        def compare_with_coercion(other)
          # if other is an ActiveSupport::TimeWithZone, coerce a Time
    instance from it so we can do <=> comparision
          other = other.comparable_time if
          if other.acts_like?(:date)
            # other is a Date/DateTime, so coerce self #to_datetime
      and hand off to DateTime#<=>

compare_without_coercion is an alias:
 alias_method :compare_without_coercion, :<=>

So: how to do this comparison? Is it a good idea to make use of
activesupport's core extensions in my own ruby programs? Is this an
activesupport bug?

Many thanks,
Jonathan G.
Jorrel (Guest)
on 2008-10-24 12:48
(Received via mailing list)
why include ActiveSupport::CoreExtensions::Time::Calculations in Time
again when active support already does it for you?
Jonathan G. (Guest)
on 2008-10-24 12:55
(Received via mailing list)
On Fri, Oct 24, 2008 at 05:45:12PM +0900, Jorrel wrote:
>why include ActiveSupport::CoreExtensions::Time::Calculations in Time
>again when active support already does it for you?

Of course, thank you. It's what you get when refactoring code.
(my code originally had a more limited require)

This topic is locked and can not be replied to.