Class: Preval::Node::TypeMatch
- Inherits:
-
Object
- Object
- Preval::Node::TypeMatch
- Defined in:
- lib/preval/node.rb
Instance Attribute Summary collapse
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(types) ⇒ TypeMatch
constructor
A new instance of TypeMatch.
- #match?(node) ⇒ Boolean
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
#types ⇒ Object (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
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
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 |