class RuboCop::Cop::Style::RedundantArrayFlatten
Checks for redundant calls of ‘Array#flatten`.
‘Array#join` joins nested arrays recursively, so flattening an array beforehand is redundant.
@safety
Cop is unsafe because the receiver of `flatten` method might not be an `Array`, so it's possible it won't respond to `join` method, or the end result would be different. Also, if the global variable `$,` is set to a value other than the default `nil`, false positives may occur.
@example
# bad x.flatten.join x.flatten(1).join # good x.join
Constants
- MSG
- RESTRICT_ON_SEND
Public Instance Methods
Source
# File lib/rubocop/cop/style/redundant_array_flatten.rb, line 38 def on_send(node) return unless flatten_join?(node.parent) range = node.loc.dot.begin.join(node.source_range.end) add_offense(range) do |corrector| corrector.remove(range) end end
Also aliased as: on_csend