Module: RuboCop::Cop::Metrics::Utils::IteratingBlock
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/rubocop/cop/metrics/utils/iterating_block.rb |
Overview
Used to identify iterating blocks like .map{}
and .map(&:…)
Constant Summary
-
KNOWN_ITERATING_METHODS =
# File 'lib/rubocop/cop/metrics/utils/iterating_block.rb', line 33(Set.new(enumerable) + enumerator + array + hash).freeze
Instance Method Summary
-
#block_method_name(node)
Returns the name of the method called with a block if node is a block node, or a block-pass node.
-
#iterating_block?(node) ⇒ Boolean
Returns nil if node is neither a block node or a block-pass node.
-
#iterating_method?(name) ⇒ Boolean
Returns true iff name is a known iterating type (e.g.
Instance Method Details
#block_method_name(node)
Returns the name of the method called with a block if node is a block node, or a block-pass node.
# File 'lib/rubocop/cop/metrics/utils/iterating_block.rb', line 37
def block_method_name(node) case node.type when :block node.method_name when :block_pass node.parent.method_name end end
#iterating_block?(node) ⇒ Boolean
Returns nil if node is neither a block node or a block-pass node. Otherwise returns true/false if method call is a known iterating call
# File 'lib/rubocop/cop/metrics/utils/iterating_block.rb', line 53
def (node) name = block_method_name(node) name && (name) end
#iterating_method?(name) ⇒ Boolean
Returns true iff name is a known iterating type (e.g. :each, :transform_values)
# File 'lib/rubocop/cop/metrics/utils/iterating_block.rb', line 47
def (name) KNOWN_ITERATING_METHODS.include? name end