Requiring ActiveSupport Extensions in Ruby

ActiveSupport is one of the gems that makes up Rails and provides a lot of useful helper methods. When working in Ruby, you can load the entire ActiveSupport library with the following command:

require "activesupport/all"

ActiveSupport is a large library and it is better to only require portions of it if possible. For example, if you would like to take advantage of the blank? method in Rails, use this line:

require 'active_support/core_ext/object/blank'

ActiveSupport time helpers are particularly useful and can be required with this line:

require 'active_support/time'

Once ActiveSupport#time is included, useful methods like ago() and months() are accessible in the Rails application.

>> 5.months.ago
=> 2013-03-13 20:05:03 -0400

The RailsGuides have more information about loading ActiveSupport Core Extensions.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s