Class: RubyNext::Language::Rewriters::Predicates::Processor

Inherits:
Parser::TreeRewriter
  • Object
show all
Defined in:
lib/ruby-next/language/rewriters/2.7/pattern_matching.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#predicatesObject (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