Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new "String#chars" rule #870

Merged
merged 1 commit into from Mar 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.adoc
Expand Up @@ -4487,6 +4487,22 @@ 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.

NOTE: These cases have the same behavior since Ruby 2.0.

[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.
Expand Down