Skip to content

Commit

Permalink
AS guide: completes section about loading AS core extensions within a…
Browse files Browse the repository at this point in the history
… Rails application
  • Loading branch information
fxn committed Mar 16, 2010
1 parent f9edf89 commit b6edffa
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions railties/guides/source/active_support_core_extensions.textile
Expand Up @@ -8,6 +8,8 @@ endprologue.


h3. How to Load Core Extensions h3. How to Load Core Extensions


h4. Stand-Alone Active Support

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. 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: Thus, after a simple require like:
Expand All @@ -18,7 +20,7 @@ require 'active_support'


objects do not even respond to +blank?+, let's see how to load its definition. objects do not even respond to +blank?+, let's see how to load its definition.


h4. Cherry-picking a Definition h5. Cherry-picking a Definition


The most lightweight way to get +blank?+ is to cherry-pick the file that defines it. The most lightweight way to get +blank?+ is to cherry-pick the file that defines it.


Expand All @@ -34,7 +36,7 @@ require 'active_support/core_ext/object/blank'


Active Support has been carefully revised so that cherry-picking a file loads only strictly needed dependencies, if any. Active Support has been carefully revised so that cherry-picking a file loads only strictly needed dependencies, if any.


h4. Loading Grouped Core Extensions h5. 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+. 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+.


Expand All @@ -44,15 +46,15 @@ Thus, if that would do, to have +blank?+ available we could just load all extens
require 'active_support/core_ext/object' require 'active_support/core_ext/object'
</ruby> </ruby>


h4. Loading All Core Extensions h5. Loading All Core Extensions


You may prefer just to load all core extensions, there is a file for that: You may prefer just to load all core extensions, there is a file for that:


<ruby> <ruby>
require 'active_support/core_ext' require 'active_support/core_ext'
</ruby> </ruby>


h4. Loading All Active Support h5. Loading All Active Support


And finally, if you want to have all Active Support available just issue: And finally, if you want to have all Active Support available just issue:


Expand All @@ -62,6 +64,10 @@ require 'active_support/all'


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. 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.


h4. Active Support Within a Ruby on Rails Application

A Ruby on Rails application loads all Active Support unless +config.active_support.bare+ is true. In that case, the application will only load what the framework itself cherry-picks for its own needs, and can still cherry-pick itself at any granularity level, as explained in the previous section.

h3. Extensions to All Objects h3. Extensions to All Objects


h4. +blank?+ and +present?+ h4. +blank?+ and +present?+
Expand Down

0 comments on commit b6edffa

Please sign in to comment.