Class: Atomy::Pattern::Or
- Inherits:
-
Atomy::Pattern
- Object
- Atomy::Pattern
- Atomy::Pattern::Or
- Defined in:
- lib/atomy/pattern/or.rb
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#b ⇒ Object
readonly
Returns the value of attribute b.
Attributes inherited from Atomy::Pattern
Instance Method Summary collapse
-
#initialize(a, b) ⇒ Or
constructor
A new instance of Or.
- #inline_matches?(gen) ⇒ Boolean
- #matches?(val) ⇒ Boolean
Methods inherited from Atomy::Pattern
Constructor Details
#initialize(a, b) ⇒ Or
Returns a new instance of Or.
7 8 9 10 |
# File 'lib/atomy/pattern/or.rb', line 7 def initialize(a, b) @a = a @b = b end |
Instance Attribute Details
#a ⇒ Object (readonly)
Returns the value of attribute a.
5 6 7 |
# File 'lib/atomy/pattern/or.rb', line 5 def a @a end |
#b ⇒ Object (readonly)
Returns the value of attribute b.
5 6 7 |
# File 'lib/atomy/pattern/or.rb', line 5 def b @b end |
Instance Method Details
#inline_matches?(gen) ⇒ Boolean
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/atomy/pattern/or.rb', line 16 def inline_matches?(gen) match = gen.new_label done = gen.new_label # [value, value] gen.dup # [bool, value] @a.inline_matches?(gen) # [value] gen.goto_if_true(match) # [bool] @b.inline_matches?(gen) # [bool] gen.goto(done) # [value] match.set! # [] gen.pop # [bool] gen.push_true # [bool] done.set! end |
#matches?(val) ⇒ Boolean
12 13 14 |
# File 'lib/atomy/pattern/or.rb', line 12 def matches?(val) @a.matches?(val) || @b.matches?(val) end |