Prefer string interpolation to string concatenation. Open
say(' ' + error, :red)
- Read upRead up
- Exclude checks
This cop checks for places where string concatenation can be replaced with string interpolation.
The cop can autocorrect simple cases but will skip autocorrecting more complex cases where the resulting code would be harder to read. In those cases, it might be useful to extract statements to local variables or methods which you can then interpolate in a string.
NOTE: When concatenation between two strings is broken over multiple
lines, this cop does not register an offense; instead,
Style/LineEndConcatenation
will pick up the offense if enabled.
Example:
# bad
email_with_name = user.name + ' '
# good
email_with_name = "#{user.name} "
email_with_name = format('%s ', user.name, user.email)
# accepted, line-end concatenation
name = 'First' +
'Last'
Prefer string interpolation to string concatenation. Open
skip_domains.each { |domain| say(' ' + domain) }
- Read upRead up
- Exclude checks
This cop checks for places where string concatenation can be replaced with string interpolation.
The cop can autocorrect simple cases but will skip autocorrecting more complex cases where the resulting code would be harder to read. In those cases, it might be useful to extract statements to local variables or methods which you can then interpolate in a string.
NOTE: When concatenation between two strings is broken over multiple
lines, this cop does not register an offense; instead,
Style/LineEndConcatenation
will pick up the offense if enabled.
Example:
# bad
email_with_name = user.name + ' '
# good
email_with_name = "#{user.name} "
email_with_name = format('%s ', user.name, user.email)
# accepted, line-end concatenation
name = 'First' +
'Last'
Redundant begin
block detected. Open
begin
- Read upRead up
- Exclude checks
This cop checks for redundant begin
blocks.
Currently it checks for code like this:
Example:
# bad
def redundant
begin
ala
bala
rescue StandardError => e
something
end
end
# good
def preferred
ala
bala
rescue StandardError => e
something
end
# bad
begin
do_something
end
# good
do_something
# bad
# When using Ruby 2.5 or later.
do_something do
begin
something
rescue => ex
anything
end
end
# good
# In Ruby 2.5 or later, you can omit `begin` in `do-end` block.
do_something do
something
rescue => ex
anything
end
# good
# Stabby lambdas don't support implicit `begin` in `do-end` blocks.
-> do
begin
foo
rescue Bar
baz
end
end
Redundant begin
block detected. Open
begin
- Read upRead up
- Exclude checks
This cop checks for redundant begin
blocks.
Currently it checks for code like this:
Example:
# bad
def redundant
begin
ala
bala
rescue StandardError => e
something
end
end
# good
def preferred
ala
bala
rescue StandardError => e
something
end
# bad
begin
do_something
end
# good
do_something
# bad
# When using Ruby 2.5 or later.
do_something do
begin
something
rescue => ex
anything
end
end
# good
# In Ruby 2.5 or later, you can omit `begin` in `do-end` block.
do_something do
something
rescue => ex
anything
end
# good
# Stabby lambdas don't support implicit `begin` in `do-end` blocks.
-> do
begin
foo
rescue Bar
baz
end
end
Prefer string interpolation to string concatenation. Open
say(' ' + error, :red)
- Read upRead up
- Exclude checks
This cop checks for places where string concatenation can be replaced with string interpolation.
The cop can autocorrect simple cases but will skip autocorrecting more complex cases where the resulting code would be harder to read. In those cases, it might be useful to extract statements to local variables or methods which you can then interpolate in a string.
NOTE: When concatenation between two strings is broken over multiple
lines, this cop does not register an offense; instead,
Style/LineEndConcatenation
will pick up the offense if enabled.
Example:
# bad
email_with_name = user.name + ' '
# good
email_with_name = "#{user.name} "
email_with_name = format('%s ', user.name, user.email)
# accepted, line-end concatenation
name = 'First' +
'Last'