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, #quantified?, #quantifier?, #quasibinding, #root, #root?, #to_a, #validate, #|
Constructor Details
Returns a new instance of PatternVariable.
274
275
276
277
278
279
|
# File 'lib/pattern-match/core.rb', line 274
def initialize(name)
super()
@name = name
@val = nil
@bind_to = nil
end
|
Instance Attribute Details
Returns the value of attribute name.
272
273
274
|
# File 'lib/pattern-match/core.rb', line 272
def name
@name
end
|
Returns the value of attribute val.
272
273
274
|
# File 'lib/pattern-match/core.rb', line 272
def val
@val
end
|
Instance Method Details
320
321
322
|
# File 'lib/pattern-match/core.rb', line 320
def inspect
"#<#{self.class.name}: name=#{name.inspect}, val=#{@val.inspect}>"
end
|
#match(vals) ⇒ Object
281
282
283
284
285
286
|
# File 'lib/pattern-match/core.rb', line 281
def match(vals)
super do |val|
bind(val)
true
end
end
|
#set_bind_to(quantifier) ⇒ Object
292
293
294
295
296
297
298
299
300
301
302
303
304
|
# File 'lib/pattern-match/core.rb', line 292
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
306
307
308
309
310
311
312
313
314
315
316
317
318
|
# File 'lib/pattern-match/core.rb', line 306
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
|
288
289
290
|
# File 'lib/pattern-match/core.rb', line 288
def vars
[self]
end
|