Class: PatternMatch::PatternVariable
Instance Attribute Summary collapse
Attributes inherited from Pattern
#next, #parent, #prev
Instance Method Summary
collapse
#quantifier?
Methods inherited from Pattern
#!@, #&, #ancestors, #append, #directly_quantified?, #quantified?, #quantifier?, #quasibinding, #root, #root?, #to_a, #validate, #|
#choice_points
Constructor Details
Returns a new instance of PatternVariable.
228
229
230
231
232
233
|
# File 'lib/pattern-match/core.rb', line 228
def initialize(name)
super()
@name = name
@val = nil
@bind_to = nil
end
|
Instance Attribute Details
Returns the value of attribute name.
226
227
228
|
# File 'lib/pattern-match/core.rb', line 226
def name
@name
end
|
Returns the value of attribute val.
226
227
228
|
# File 'lib/pattern-match/core.rb', line 226
def val
@val
end
|
Instance Method Details
#<<(converter) ⇒ Object
158
159
160
161
|
# File 'lib/pattern-match/experimental.rb', line 158
def <<(converter)
@converter = converter.respond_to?(:call) ? converter : converter.to_proc
self
end
|
274
275
276
|
# File 'lib/pattern-match/core.rb', line 274
def inspect
"#<#{self.class.name}: name=#{name.inspect}, val=#{@val.inspect}>"
end
|
#match(vals) ⇒ Object
235
236
237
238
239
240
|
# File 'lib/pattern-match/core.rb', line 235
def match(vals)
super do |val|
bind(val)
true
end
end
|
#set_bind_to(quantifier) ⇒ Object
246
247
248
249
250
251
252
253
254
255
256
257
258
|
# File 'lib/pattern-match/core.rb', line 246
def set_bind_to(quantifier)
n = nest_level(quantifier)
if n == 0
@val = @bind_to = []
else
outer = @val
(n - 1).times do
outer = outer[-1]
end
@bind_to = []
outer << @bind_to
end
end
|
#unset_bind_to(quantifier) ⇒ Object
260
261
262
263
264
265
266
267
268
269
270
271
272
|
# File 'lib/pattern-match/core.rb', line 260
def unset_bind_to(quantifier)
n = nest_level(quantifier)
@bind_to = nil
if n == 0
else
outer = @val
(n - 1).times do
outer = outer[-1]
end
outer.pop
end
end
|
242
243
244
|
# File 'lib/pattern-match/core.rb', line 242
def vars
[self]
end
|