Skip to content

Commit fdabc17

Browse files
author
Malcolm Locke
committed
Change core_ext cherry picking example.
`Object#blank?` is used as an example in this guide of a core extension that is not loaded by default in Active Support, and how to load it manually. However it now _is_ loaded by default. This change gives a different example (`Hash#with_indifferent_access`) that will hopefully be less likely to be pulled into the default requires in future.
1 parent a31f764 commit fdabc17

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

guides/source/active_support_core_extensions.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,46 @@ How to Load Core Extensions
2121

2222
### Stand-Alone Active Support
2323

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

2626
Thus, after a simple require like:
2727

2828
```ruby
2929
require "active_support"
3030
```
3131

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

3434
#### Cherry-picking a Definition
3535

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

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+
```
3941

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

4246
That means that you can require it like this:
4347

4448
```ruby
4549
require "active_support"
46-
require "active_support/core_ext/object/blank"
50+
require "active_support/core_ext/hash/indifferent_access"
4751
```
4852

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

5155
#### Loading Grouped Core Extensions
5256

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

55-
Thus, to load all extensions to `Object` (including `blank?`):
59+
Thus, to load all extensions to `Hash` (including `with_indifferent_access`):
5660

5761
```ruby
5862
require "active_support"
59-
require "active_support/core_ext/object"
63+
require "active_support/core_ext/hash"
6064
```
6165

6266
#### Loading All Core Extensions

0 commit comments

Comments
 (0)