Class: RubyNext::Language::Rewriters::Predicates::Processor
- Inherits:
-
Parser::TreeRewriter
- Object
- Parser::TreeRewriter
- RubyNext::Language::Rewriters::Predicates::Processor
- Defined in:
- lib/ruby-next/language/rewriters/2.7/pattern_matching.rb
Instance Attribute Summary collapse
-
#predicates ⇒ Object
readonly
Returns the value of attribute predicates.
Instance Method Summary collapse
-
#initialize(predicates) ⇒ Processor
constructor
A new instance of Processor.
- #on_and(node) ⇒ Object
- #on_lvasgn(node) ⇒ Object
Constructor Details
#initialize(predicates) ⇒ Processor
Returns a new instance of Processor.
68 69 70 71 |
# File 'lib/ruby-next/language/rewriters/2.7/pattern_matching.rb', line 68 def initialize(predicates) @predicates = predicates super() end |
Instance Attribute Details
#predicates ⇒ Object (readonly)
Returns the value of attribute predicates.
66 67 68 |
# File 'lib/ruby-next/language/rewriters/2.7/pattern_matching.rb', line 66 def predicates @predicates end |
Instance Method Details
#on_and(node) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/ruby-next/language/rewriters/2.7/pattern_matching.rb', line 82 def on_and(node) left, right = *node.children if truthy(left) process(right) elsif truthy(right) process(left) else node.updated( :and, [ process(left), process(right) ] ) end end |
#on_lvasgn(node) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/ruby-next/language/rewriters/2.7/pattern_matching.rb', line 73 def on_lvasgn(node) lvar, val = *node.children if predicates.store[lvar] == false process(val) else node end end |