Class: CodeNode::IR::NodeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/code_node/ir/node_matcher.rb

Overview

Encapsulates a pattern match test for nodes

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ NodeMatcher

Returns a new instance of NodeMatcher.



8
9
10
# File 'lib/code_node/ir/node_matcher.rb', line 8

def initialize(pattern)
  @pattern = pattern
end

Instance Method Details

#matches?(node) ⇒ Boolean

Returns does the node match?.

Parameters:

Returns:

  • (Boolean)

    does the node match?



14
15
16
17
18
19
20
21
22
# File 'lib/code_node/ir/node_matcher.rb', line 14

def matches?(node)
  if @pattern.is_a? Proc
    @pattern.call node
  elsif @pattern.is_a? Regexp
    @pattern =~ node.path
  else
    @pattern.to_s == node.path
  end
end