123456789_123456789_123456789_123456789_123456789_

Module: RuboCop::Cop::Metrics::Utils::RepeatedCsendDiscount Private

Do not use. This module is for internal use only.

Overview

Identifies repetitions &. on the same variable:

my_var&.foo
my_var&.bar # => repeated
my_var = baz # => reset
my_var&.qux # => not repeated

Instance Method Summary

Instance Method Details

#discount_for_repeated_csend?(csend_node) ⇒ Boolean

[ GitHub ]

  
# File 'lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb', line 20

def discount_for_repeated_csend?(csend_node)
  receiver = csend_node.receiver

  return false unless receiver.lvar_type?

  var_name = receiver.children.first
  seen = @repeated_csend.fetch(var_name) do
    @repeated_csend[var_name] = csend_node
    return false
  end

  !seen.equal?(csend_node)
end

#reset_on_lvasgn(node)

[ GitHub ]

  
# File 'lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb', line 34

def reset_on_lvasgn(node)
  var_name = node.children.first
  @repeated_csend.delete(var_name)
end

#reset_repeated_csend

[ GitHub ]

  
# File 'lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb', line 16

def reset_repeated_csend
  @repeated_csend = {}
end