123456789_123456789_123456789_123456789_123456789_

Module: RuboCop::Cop::PatternMatchingHelp

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: lib/rubocop/cop/mixin/pattern_matching_help.rb

Overview

Common functionality for checking whether a node is used in a pattern of pattern matching, where only some expressions are allowed.

Constant Summary

Instance Method Summary

Instance Method Details

#in_pattern?(node) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/pattern_matching_help.rb', line 15

def in_pattern?(node)
  child = node

  node.each_ancestor do |ancestor|
    case ancestor.type
    when :in_pattern
      return ancestor.pattern.equal?(child)
    when :match_pattern, :match_pattern_p
      return ancestor.children[1].equal?(child)
    when *PATTERN_TYPES
      child = ancestor
    else
      return false
    end
  end

  false
end