Module: RuboCop::Cop::Metrics::Utils::RepeatedCsendDiscount Private
Do not use. This module is for internal use only.
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb |
Overview
Identifies repetitions &.
on the same variable:
my_var&.foo
my_var&. # => repeated
my_var = baz # => reset
my_var&.qux # => not repeated
Instance Method Summary
- #discount_for_repeated_csend?(csend_node) ⇒ Boolean Internal use only
- #reset_on_lvasgn(node) Internal use only
- #reset_repeated_csend Internal use only
Instance Method Details
#discount_for_repeated_csend?(csend_node) ⇒ Boolean
# 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