You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/source/active_support_core_extensions.md
+13-9Lines changed: 13 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,42 +21,46 @@ How to Load Core Extensions
21
21
22
22
### Stand-Alone Active Support
23
23
24
-
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 can load just what you need, and also has some convenience entry points to load related extensions in one shot, even everything.
24
+
In order to have the smallest default footprint possible, Active Support loads the minimum dependencies by default. It is broken in small pieces so that only the desired extensions can be loaded. It also has some convenience entry points to load related extensions in one shot, even everything.
25
25
26
26
Thus, after a simple require like:
27
27
28
28
```ruby
29
29
require"active_support"
30
30
```
31
31
32
-
objects do not even respond to [`blank?`][Object#blank?]. Let's see how to load its definition.
32
+
only the extensions required by the Active Support framework are loaded.
33
33
34
34
#### Cherry-picking a Definition
35
35
36
-
The most lightweight way to get `blank?` is to cherry-pick the file that defines it.
36
+
This example shows how to load [`Hash#with_indifferent_access`][Hash#with_indifferent_access]. This extension enables the conversion of a `Hash` into an [`ActiveSupport::HashWithIndifferentAccess`][ActiveSupport::HashWithIndifferentAccess] which permits access to the keys as either strings or symbols.
37
37
38
-
For every single method defined as a core extension this guide has a note that says where such a method is defined. In the case of `blank?` the note reads:
38
+
```ruby
39
+
{a:1}.with_indifferent_access["a"] # => 1
40
+
```
39
41
40
-
NOTE: Defined in `active_support/core_ext/object/blank.rb`.
42
+
For every single method defined as a core extension this guide has a note that says where such a method is defined. In the case of `with_indifferent_access` the note reads:
43
+
44
+
NOTE: Defined in `active_support/core_ext/hash/indifferent_access.rb`.
Active Support has been carefully revised so that cherry-picking a file loads only strictly needed dependencies, if any.
50
54
51
55
#### Loading Grouped Core Extensions
52
56
53
-
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`.
57
+
The next level is to simply load all extensions to `Hash`. As a rule of thumb, extensions to `SomeClass` are available in one shot by loading `active_support/core_ext/some_class`.
54
58
55
-
Thus, to load all extensions to `Object` (including `blank?`):
59
+
Thus, to load all extensions to `Hash` (including `with_indifferent_access`):
0 commit comments