From c58b7c91c84e935b1641608524a2c8416d913af3 Mon Sep 17 00:00:00 2001 From: viralpraxis Date: Sat, 11 Oct 2025 14:36:39 +0400 Subject: [PATCH] Prefer JSON's `symbolize_names` option instead of ActiveSupport's `deep_symbolize_keys` ref: https://github.com/rubocop/rubocop-rails/pull/1534 --- README.adoc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.adoc b/README.adoc index cf59a43..8a56d81 100644 --- a/README.adoc +++ b/README.adoc @@ -1727,6 +1727,23 @@ hash.exclude?(:key) string.exclude?('substring') ---- +=== `deep_symbolize_keys` [[deep-symbolize-keys]] + +Prefer JSON's `symbolize_names` keyword argument instead of chaining `deep_symbolize_keys`. + +Using `symbolize_names: true` is more efficient as it creates symbols during parsing +rather than requiring a second pass through the data structure. + +[source,ruby] +---- +# bad +JSON.parse(data).deep_symbolize_keys +JSON.parse(data).deep_transform_keys(&:to_sym) + +# good +JSON.parse(data, symbolize_names: true) +---- + === Prefer using squiggly heredoc over `strip_heredoc` [[prefer-squiggly-heredoc]] If you're using Ruby 2.3 or higher, prefer squiggly heredoc (`<<~`) over Active Support's `strip_heredoc`.