diff options
Diffstat (limited to 'railties/guides')
-rw-r--r-- | railties/guides/source/active_support_core_extensions.textile | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 368dcc00b6..11f0bc956f 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -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?+ |