Skip to content

Commit c58b7c9

Browse files
committed
Prefer JSON's symbolize_names option instead of ActiveSupport's deep_symbolize_keys
ref: rubocop/rubocop-rails#1534
1 parent 86bffd4 commit c58b7c9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.adoc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,23 @@ hash.exclude?(:key)
17271727
string.exclude?('substring')
17281728
----
17291729

1730+
=== `deep_symbolize_keys` [[deep-symbolize-keys]]
1731+
1732+
Prefer JSON's `symbolize_names` keyword argument instead of chaining `deep_symbolize_keys`.
1733+
1734+
Using `symbolize_names: true` is more efficient as it creates symbols during parsing
1735+
rather than requiring a second pass through the data structure.
1736+
1737+
[source,ruby]
1738+
----
1739+
# bad
1740+
JSON.parse(data).deep_symbolize_keys
1741+
JSON.parse(data).deep_transform_keys(&:to_sym)
1742+
1743+
# good
1744+
JSON.parse(data, symbolize_names: true)
1745+
----
1746+
17301747
=== Prefer using squiggly heredoc over `strip_heredoc` [[prefer-squiggly-heredoc]]
17311748

17321749
If you're using Ruby 2.3 or higher, prefer squiggly heredoc (`<<~`) over Active Support's `strip_heredoc`.

0 commit comments

Comments
 (0)