Class: Algebrick::Matchers::Abstract
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from TypeCheck
#Child!, #Child?, #Match!, #Match?, #Type!, #Type?
Constructor Details
Returns a new instance of Abstract.
21
22
23
|
# File 'lib/algebrick/matchers/abstract.rb', line 21
def initialize
@assign, @value, @matched = nil
end
|
Instance Attribute Details
Returns the value of attribute value.
19
20
21
|
# File 'lib/algebrick/matchers/abstract.rb', line 19
def value
@value
end
|
Instance Method Details
52
53
54
|
# File 'lib/algebrick/matchers/abstract.rb', line 52
def !
Not.new self
end
|
#&(matcher) ⇒ Object
44
45
46
|
# File 'lib/algebrick/matchers/abstract.rb', line 44
def &(matcher)
And.new self, matcher
end
|
#==(other) ⇒ Object
102
103
104
|
# File 'lib/algebrick/matchers/abstract.rb', line 102
def ==(other)
raise NotImplementedError
end
|
#===(other) ⇒ Object
82
83
84
|
# File 'lib/algebrick/matchers/abstract.rb', line 82
def ===(other)
matching?(other).tap { |matched| @value = other if (@matched = matched) }
end
|
#>(block) ⇒ Object
Also known as:
>>
31
32
33
|
# File 'lib/algebrick/matchers/abstract.rb', line 31
def >(block)
return self, block
end
|
#assign! ⇒ Object
Also known as:
~
37
38
39
40
|
# File 'lib/algebrick/matchers/abstract.rb', line 37
def assign!
@assign = true
self
end
|
56
57
58
|
# File 'lib/algebrick/matchers/abstract.rb', line 56
def assign?
@assign
end
|
#assign_to_s ⇒ Object
86
87
88
|
# File 'lib/algebrick/matchers/abstract.rb', line 86
def assign_to_s
assign? ? '~' : ''
end
|
60
61
62
|
# File 'lib/algebrick/matchers/abstract.rb', line 60
def assigned?
!!@value
end
|
72
73
74
75
76
|
# File 'lib/algebrick/matchers/abstract.rb', line 72
def assigns
collect_assigns.tap do
return yield *assigns if block_given?
end
end
|
#case(&block) ⇒ Object
Also known as:
when
25
26
27
|
# File 'lib/algebrick/matchers/abstract.rb', line 25
def case(&block)
return self, block
end
|
94
95
96
|
# File 'lib/algebrick/matchers/abstract.rb', line 94
def children
raise NotImplementedError
end
|
#children_including_self ⇒ Object
68
69
70
|
# File 'lib/algebrick/matchers/abstract.rb', line 68
def children_including_self
children.unshift self
end
|
90
91
92
|
# File 'lib/algebrick/matchers/abstract.rb', line 90
def inspect
to_s
end
|
64
65
66
|
# File 'lib/algebrick/matchers/abstract.rb', line 64
def matched?
@matched
end
|
78
79
80
|
# File 'lib/algebrick/matchers/abstract.rb', line 78
def to_a
assigns
end
|
98
99
100
|
# File 'lib/algebrick/matchers/abstract.rb', line 98
def to_s
raise NotImplementedError
end
|
#|(matcher) ⇒ Object
48
49
50
|
# File 'lib/algebrick/matchers/abstract.rb', line 48
def |(matcher)
Or.new self, matcher
end
|