Class: Preval::Node::TypeMatch

Inherits:
Object
  • Object
show all
Defined in:
lib/preval/node.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types) ⇒ TypeMatch

Returns a new instance of TypeMatch.



8
9
10
# File 'lib/preval/node.rb', line 8

def initialize(types)
  @types = types
end

Instance Attribute Details

#typesObject (readonly)

Returns the value of attribute types.



6
7
8
# File 'lib/preval/node.rb', line 6

def types
  @types
end

Class Method Details

.match?(types, node) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/preval/node.rb', line 19

def self.match?(types, node)
  new(types).match?(node)
end

Instance Method Details

#match?(node) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
# File 'lib/preval/node.rb', line 12

def match?(node)
  node.body.size == types.size &&
    node.body.zip(types).all? do |(left, right)|
      left.is_a?(Node) && Array(right).include?(left.type)
    end
end