From 0760beab250c5b1f0183db2d06e886193a8a442d Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sat, 20 Mar 2021 01:20:44 +0900 Subject: [PATCH] Add new "String#chars" rule Follow https://github.com/rubocop/rubocop/pull/9615. This PR adds "String#chars" rule. ```ruby # bad string.split(//) string.split('') # good string.chars ``` --- README.adoc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.adoc b/README.adoc index bcdc28c8c..d875f2bbd 100644 --- a/README.adoc +++ b/README.adoc @@ -4487,6 +4487,20 @@ url.sub('http://', 'https://') str.tr('-', '_') ---- +=== `String#chars` [[string-chars]] + +Prefer the use of `String#chars` over `String#split` with empty string or regexp literal argument. + +[source,ruby] +---- +# bad +string.split(//) +string.split('') + +# good +string.chars +---- + === `sprintf` [[sprintf]] Prefer the use of `sprintf` and its alias `format` over the fairly cryptic `String#%` method.