1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

AS guide: How to Load Core Extensions

This commit is contained in:
Xavier Noria 2010-03-03 19:58:44 +01:00
parent a368f3b170
commit 71b29d1e56

View file

@ -6,6 +6,62 @@ By referring to this guide you will learn the extensions to the Ruby core classe
endprologue.
h3. How to Load Core Extensions
In order to have a near zero default footprint, Active Support does not load anything by default. It is broken in small pieces so that you may load just what you need, and also has some convenience entry points to load related extensions in one shot, even everything.
Thus, after a simple require like:
<ruby>
require 'active_support'
</ruby>
objects do not even respond to +blank?+, let's see how to load its definition.
h4. Cherry-picking a Definition
The most lightweight way to get +blank?+ is to cherry-pick the file that defines it.
For every single method defined as a core extension this guide has a note that says where is such a method defined. In the case of +blank?+ the note reads:
NOTE: Defined in +active_support/core_ext/object/blank.rb+.
That means that this single call is enough:
<ruby>
require 'active_support/core_ext/object/blank'
</ruby>
Active Support has been carefully revised so that cherry-picking a file loads only strictly needed dependencies, if any.
h4. Loading Grouped Core Extensions
The next level is to simply load all extensions to +Object+. As a rule of thumb, extensions to +SomeClass+ are available in one shot by loading +active_support/core_ext/some_class+.
Thus, if that would do, to have +blank?+ available we could just load all extensions to +Object+:
<ruby>
require 'active_support/core_ext/object'
</ruby>
h4. Loading All Core Extensions
You may prefer just to load all core extensions, there is a file for that:
<ruby>
require 'active_support/core_ext'
</ruby>
h4. Loading All Active Support
And finally, if you want to have all Active Support available just issue:
<ruby>
require 'active_support/all'
</ruby>
That does not even put the entire Active Support in memory upfront indeed, some stuff is configured via +autoload+, so it is only loaded if used.
h3. Extensions to All Objects
h4. +blank?+ and +present?+