#825 ✓resolved
Hussein Morsy

NameError Exception with dm-core (extlib) 0.9.11 and ActiveSuport

Reported by Hussein Morsy | March 30th, 2009 @ 07:42 AM

you can't use ActiveSupport with dm-core in version 0.9.11:

require 'rubygems'
require 'active_support'
require 'dm-core'      

=> Exception

NameError: method ‘to_time’ not defined in Time
method remove_method	in time.rb at line 26

The cause is the extlib: The same exception occur here:

require 'rubygems'
require 'active_support'
require 'exitlib'      

Comments and changes to this ticket

  • Hussein Morsy

    Hussein Morsy March 30th, 2009 @ 08:19 AM

    The Cause is commit 74c7e2 of datamapper/extlib

    file lib/extlib/datetime.rb #12 and lib/extlib/time.rb #12

    remove_method :to_time if method_defined?(:to_time) || private_method_defined?(:to_time)

    file lib/extlib/datetime.rb #25

     remove_method :to_datetime if method_defined?(:to_datetime) || private_method_defined?(:to_datetime)

    The Problem is, that method_defined? returns true no only if the named method is defined by the class, but also if the method is defined by its ancestors or its included modules.

    i transmitted a pull request.

    the following code solves the problem:

    remove_method :to_time if instance_methods.include?(:to_time)
  • joel hansson

    joel hansson April 3rd, 2009 @ 10:43 AM

    I can confirm this ticket.

    And the fix by Hussein Morsy works for me.

  • Stephen Bannasch

    Stephen Bannasch April 12th, 2009 @ 09:12 PM

    and line 12 of lib/extlib/datetime.rb

    diff --git a/lib/extlib/datetime.rb b/lib/extlib/datetime.rb
    index fd118bb..0163228 100644
    --- a/lib/extlib/datetime.rb
    +++ b/lib/extlib/datetime.rb
    @@ -9,7 +9,7 @@ class DateTime
       # @return [Time] Time object representing the same moment as receiver
       # @api public
    -  remove_method :to_time if method_defined?(:to_time) || private_method_defined?(:to_time)
    +  remove_method :to_time if instance_methods.include?(:to_time)
       def to_time
         Time.parse self.to_s
    @@ -22,7 +22,7 @@ class DateTime
       # @return [DateTime] Receiver
       # @api public
    -  remove_method :to_datetime if method_defined?(:to_datetime) || private_method_defined?(:to_datetime)
    +  remove_method :to_datetime if instance_methods.include?(:to_datetime)
       def to_datetime

    There are 3 other places remove_method uses this pattern -- I have not looked at changing these:

    spec/lazy_array_spec.rb 1916: remove_method :lazy_spec if method_defined?(:lazy_spec) || private_method_defined?(:lazy_spec)

    spec/pooling_spec.rb 6: remove_method :scavenger_interval if method_defined?(:scavenger_interval) || private_method_defined?(:scavenger_interval) 59: remove_method :pool_size if method_defined?(:pool_size) || private_method_defined?(:pool_size)

    I have this problem using the sproutcore server:

    $ sc-server
    /Library/Ruby/Gems/1.8/gems/extlib-0.9.11/lib/extlib/datetime.rb:26:in `remove_method': method `to_datetime' not defined in DateTime (NameError)
        from /Library/Ruby/Gems/1.8/gems/extlib-0.9.11/lib/extlib/datetime.rb:26
        from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
        from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require'
        from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
        from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require'
        from /Library/Ruby/Gems/1.8/gems/extlib-0.9.11/lib/extlib.rb:23
        from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
         ... 9 levels...
        from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require'
        from /Library/Ruby/Gems/1.8/gems/sproutcore-0.9.23/bin/sc-server:13
        from /usr/bin/sc-server:19:in `load'
        from /usr/bin/sc-server:19

    making these four changes in time.rb and datetime.rb fixed the problem for me.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) April 17th, 2009 @ 02:01 AM

    • State changed from “unconfirmed” to “confirmed”
    • Assigned user set to “Dan Kubb (dkubb)”

    Can you guys test out http://github.com/datamapper/ext... and let me know if it fixes the problems you were having?

  • Hussein Morsy

    Hussein Morsy April 18th, 2009 @ 11:36 AM

    sorry, same error:


    # Module ExtTime defined be an other library
    module ExtTime
      def to_time
    # Class Time extended  by an other library e.g. ActiveSupport
    class Time
      include ExtTime
    # Class Time extended by extlib
    class Time
      remove_method :to_time if instance_methods.any? { |m| m.to_sym == :to_time }
      def to_time

    Exception:NameError: method ‘to_time’ not defined in Time

    The cause is: The Method instance_methods by default return all also instance methods from its ancestors or its included modules. But instance_methods(false) returns only the instance methods directly defined in the class.:

    the following code works:

    # Class Time overridden by extlib
    class Time
      remove_method :to_time if instance_methods(false).any? { |m| m.to_sym == :to_time }
    in my first post i forgot to mention the <code>false</code> paramter for the method <code>instance_methods</code>. Sorry. (see APIDock http://apidock.com/ruby/Module/instance_methods)
    By the way: Why is it necessary to remove the existing <code>to_time</code> method ? Is it not allowed to  simply overright the Method without removing it ?
  • Hussein Morsy

    Hussein Morsy April 18th, 2009 @ 11:52 AM

    the problem mentioned in the SproutCore Google Group:http://groups.google.com/group/sproutcore/browse_thread/thread/f4dfe044e9ac80c8

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) April 18th, 2009 @ 01:36 PM

    The reason for the removal of :to_time prior to patching it, is that I believe libraries should run clean with warnings turned on. I realize that's not a very common viewpoint but I think it should be for anyone who cares about the quality of their library.

    I began making extlib and DataMapper "warnings safe" since the last release, but I guess there are a few things still to be ironed out. Once I do I'll post a message someplace with what I learn about the process so that others can do the same to their gems if they wish.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) April 20th, 2009 @ 12:48 AM

    @Hussein: I just committed the fix you mentioned in your last comment. Would you mind installing extlib from the "next" branch and let me know if it fixes your problem?

    If it does I can release a new extlib shortly to correct the incompatibility with ActiveSupport.

  • Hussein Morsy

    Hussein Morsy April 20th, 2009 @ 06:36 AM

    the problem with active support is now fixed. Thanks !!!

  • Bobby Wilson

    Bobby Wilson April 27th, 2009 @ 10:00 AM

    @Hussein what version of ActiveSupport are you running? I am running 2.3.2 and I still get the error with the 'next' branch of extlib.

  • Bobby Wilson

    Bobby Wilson April 27th, 2009 @ 10:22 AM

    Sorry, that last comment is incorrect, I was able to get it to work

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) April 29th, 2009 @ 12:44 AM

    • State changed from “confirmed” to “resolved”

    Awesome. I am marking this ticket as resolved.

    A new version of extlib will be released shortly.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »