# Problem with using active support core extensions in my own ruby programs

**URL:** <https://www.ruby-forum.com/t/problem-with-using-active-support-core-extensions-in-my-own-ruby-programs/151676>\
**Category:** Ruby\
**Created:** [October 24, 2008, 10:42am UTC](https://www.ruby-forum.com/t/problem-with-using-active-support-core-extensions-in-my-own-ruby-programs/151676 "2008-10-24T10:42:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgeggatt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jgeggatt](https://www.ruby-forum.com/u/jgeggatt)\
**Post date:** [October 24, 2008, 10:42am UTC](https://www.ruby-forum.com/t/problem-with-using-active-support-core-extensions-in-my-own-ruby-programs/151676/1 "2008-10-24T10:42:20Z")

</div>

This code used to perform correctly with activesupport 2.0.2:

#!/usr/bin/ruby  
require ‘rubygems’  
require ‘time’  
require ‘active\_support’

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

nxt = Time.now.change(:hour =\> 7)  
nxt = nxt.tomorrow if nxt \< Time.now  
puts nxt

* * *

However, with activesupport 2.1.2 it now fails:  
/var/lib/gems/1.8/gems/activesupport-2.1.2/lib/active\_support/core\_ext/time/calculations.rb:270:in  
‘compare\_without\_coercion’: stack level too deep (SystemStackError)  
from  
/var/lib/gems/1.8/gems/activesupport-2.1.2/lib/active\_support/core\_ext/time/calculations.rb:270:in  
‘\<=\>’  
from ./problem\_for\_ruby.ml:11:in ‘\<’  
from ./problem\_for\_ruby.ml:11

The above is obviously caused by the comparison:  
if nxt \< Time.now

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  
other.respond\_to?(:comparable\_time)  
if other.acts\_like?(:date)  
# other is a Date/DateTime, so coerce self #to\_datetime  
and hand off to DateTime#\<=\>  
to\_datetime.compare\_without\_coercion(other)  
else  
compare\_without\_coercion(other)  
end  
end

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.

---

<div class="post-metadata">

**Author:** ![jgeggatt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jgeggatt](https://www.ruby-forum.com/u/jgeggatt)\
**Post date:** [October 24, 2008, 10:48am UTC](https://www.ruby-forum.com/t/problem-with-using-active-support-core-extensions-in-my-own-ruby-programs/151676/2 "2008-10-24T10:48:13Z")

</div>

why include ActiveSupport::CoreExtensions::Time::Calculations in Time  
again when active support already does it for you?

---

<div class="post-metadata">

**Author:** ![jgeggatt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jgeggatt](https://www.ruby-forum.com/u/jgeggatt)\
**Post date:** [October 24, 2008, 10:55am UTC](https://www.ruby-forum.com/t/problem-with-using-active-support-core-extensions-in-my-own-ruby-programs/151676/3 "2008-10-24T10:55:51Z")

</div>

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)

Cheers,  
Jonathan.
