class RuboCop::Cop::Performance::RedundantMerge::EachWithObjectInspector
A utility class for checking the use of values within an `each_with_object` call.
Attributes
node[R]
receiver[R]
Public Class Methods
new(node, receiver)
click to toggle source
# File lib/rubocop/cop/performance/redundant_merge.rb, line 143 def initialize(node, receiver) @node = node @receiver = unwind(receiver) end
Public Instance Methods
value_used?()
click to toggle source
# File lib/rubocop/cop/performance/redundant_merge.rb, line 148 def value_used? return false unless eligible_receiver? && second_argument receiver.loc.name.source == second_argument.loc.name.source end
Private Instance Methods
eligible_receiver?()
click to toggle source
# File lib/rubocop/cop/performance/redundant_merge.rb, line 158 def eligible_receiver? receiver.respond_to?(:lvar_type?) && receiver.lvar_type? end
second_argument()
click to toggle source
# File lib/rubocop/cop/performance/redundant_merge.rb, line 162 def second_argument parent = node.parent parent = parent.parent if parent.begin_type? @second_argument ||= each_with_object_node(parent) end
unwind(receiver)
click to toggle source
# File lib/rubocop/cop/performance/redundant_merge.rb, line 169 def unwind(receiver) while receiver.respond_to?(:send_type?) && receiver.send_type? receiver, = *receiver end receiver end