Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveSupport 3 doesn't autoload core extensions

#3994

Update: In fact it seems none of ActiveSupport's core extensions are autoloaded anymore. Is that intentional?

If so, it would seem unwise. There's a plethora of libraries out there which depend on those core extensions. I just ran into another related issue where requiring ActiveMerchant fails because it depends on the existence of HashWithIndifferentAccess.


require 'rubygems'
require 'active_support'
class Person
  cattr_accessor :type
end

results in:

NoMethodError: undefined method 'cattr_accessor' for Person:Class from (irb):4

The old (and deprecated) loading method of "require 'activesupport'" works just fine though:

require 'rubygems'
require 'activesupport'
class Person
  cattr_accessor :type
end

This raises no error and works as expected.

Reported by Marc Love · February 18th, 2010 @ 09:24 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Marc Love
    Marc Love
    • Tag changed from activesupport, cattr_accessor to active_support core_ext, activesupport, core_ext
    • Title changed from require "active_support" doesn't provide cattr_accessor method to ActiveSupport 3 doesn't autoload core extensions

    February 18th, 2010 @ 10:49 PM

  2. Jacques Crocker
    Jacques Crocker

    Pretty sure this is intentional. If you want everything in active_support you need to use require 'active_support/all'

    That's generally a terrible idea though. The best approach for ActiveSupport 3.0 is to pick out the exact require that you need for the feature you are using. That way you avoid the overhead of loading the entire library.

    February 19th, 2010 @ 08:29 AM

  3. Marc Love
    Marc Love

    Good to know Jacques. Thanks for the info.

    It would be nice if the core team would mention this on the Rails blog. I'm sure there's going to be plenty of gem/plugin repositories out there that are going to need updating.

    February 19th, 2010 @ 10:39 PM

  4. José Valim
    José Valim
    • State changed from new to invalid

    Yup, this is intentional as discussed in the mailing list.

    February 23rd, 2010 @ 09:31 PM