Class: Atomy::Pattern::And
- Inherits:
-
Atomy::Pattern
- Object
- Atomy::Pattern
- Atomy::Pattern::And
- Defined in:
- lib/atomy/pattern/and.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
- #assign(gen) ⇒ Object
-
#initialize(a, b) ⇒ And
constructor
A new instance of And.
- #inline_matches?(gen) ⇒ Boolean
- #matches?(val) ⇒ Boolean
- #target ⇒ Object
Methods inherited from Atomy::Pattern
Constructor Details
#initialize(a, b) ⇒ And
Returns a new instance of And.
7 8 9 10 |
# File 'lib/atomy/pattern/and.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/and.rb', line 5 def a @a end |
#b ⇒ Object (readonly)
Returns the value of attribute b.
5 6 7 |
# File 'lib/atomy/pattern/and.rb', line 5 def b @b end |
Instance Method Details
#assign(gen) ⇒ Object
48 49 50 51 |
# File 'lib/atomy/pattern/and.rb', line 48 def assign(gen) @a.assign(gen) @b.assign(gen) end |
#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/and.rb', line 16 def inline_matches?(gen) mismatch = gen.new_label done = gen.new_label # [value, value] gen.dup # [bool, value] @a.inline_matches?(gen) # [value] gen.goto_if_false(mismatch) # [bool] @b.inline_matches?(gen) # [bool] gen.goto(done) # [value] mismatch.set! # [] gen.pop # [bool] gen.push_false # [bool] done.set! end |
#matches?(val) ⇒ Boolean
12 13 14 |
# File 'lib/atomy/pattern/and.rb', line 12 def matches?(val) @a.matches?(val) && @b.matches?(val) end |
#target ⇒ Object
53 54 55 56 57 |
# File 'lib/atomy/pattern/and.rb', line 53 def target a = @a.target b = @b.target a < b ? a : b end |