Reason #97 • April 7th, 2026

Extending Ruby with ActiveSupport

Last week we looked at monkey patching and how it can be used to extend Ruby's built-in classes with new methods. The canonical example of how this is used in the wild is ActiveSupport, a large collection of utility methods and standard library extensions that are part of Rails but can also be used independently.

To add ActiveSupport to a project, add activesupport to your Gemfile. Then you can choose whether to require the whole library or just the parts you need:

Ruby
# Enable a subset of extensions for a specific class:
require "active_support/core_ext/string/exclude"

"hello world".exclude?("world")
# => false

# Enable all extensions for a specific class:
require "active_support/core_ext/string"

" hello  world ".squish
# => "hello world"

# Enable everything
require "active_support/all"

%w[foo bar baz].to_sentence
# => "foo, bar, and baz"
    

In upcoming reasons, we'll zoom in on some of the most useful methods that ActiveSupport provides!

From extension to standard library

Many methods added by ActiveSupport have eventually made their way into Ruby's standard library. This is a testament to the quality and utility of the extensions provided by ActiveSupport, and it also means that we can enjoy these methods without having to depend on the whole library.

Some examples include:

History

During the first few years of Rails, there were a few competing libraries extending Ruby's standard library, and there wasn't overwhelming consensus within the community on which one to use.

The main critique of ActiveSupport at the time was that it was too heavy and included too many methods that were not relevant to all users.

To address this, ActiveSupport was heavily refactored for the Rails 3 release in 2010. This brought a more fine-grained modular structure to the library, allowing users to require only the parts they needed. This made it less controversial to use in non-Rails projects, and it ended up becoming the de facto standard for Ruby extensions in the community.

Reason #98 ?