Class: Hone::Patterns::ParallelAssignment
- Defined in:
- lib/hone/patterns/parallel_assignment.rb
Overview
Pattern: Sequential array index assignments -> parallel assignment
When assigning multiple variables from sequential array indices (0, 1, 2...), Ruby's parallel assignment syntax is more idiomatic and can be slightly faster as it avoids multiple array access operations.
Example:
# Before
a = arr[0]
b = arr[1]
c = arr[2]
# After
a, b, c = arr
Impact: Minor performance improvement, but more idiomatic Ruby
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#add_finding, inherited, #initialize, scan_file
Constructor Details
This class inherits a constructor from Hone::Patterns::Base
Instance Method Details
#visit_begin_node(node) ⇒ Object
30 31 32 33 |
# File 'lib/hone/patterns/parallel_assignment.rb', line 30 def visit_begin_node(node) check_sequential_assignments(node.statements&.body || []) super end |
#visit_statements_node(node) ⇒ Object
25 26 27 28 |
# File 'lib/hone/patterns/parallel_assignment.rb', line 25 def visit_statements_node(node) check_sequential_assignments(node.body) super end |