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.
229
230
231
232
233
234
|
# File 'lib/pattern-match/core.rb', line 229
def initialize(name)
super()
@name = name
@val = nil
@bind_to = nil
end
|
Instance Attribute Details
Returns the value of attribute name.
227
228
229
|
# File 'lib/pattern-match/core.rb', line 227
def name
@name
end
|
Returns the value of attribute val.
227
228
229
|
# File 'lib/pattern-match/core.rb', line 227
def val
@val
end
|
Instance Method Details
#<<(converter) ⇒ Object
164
165
166
167
|
# File 'lib/pattern-match/experimental.rb', line 164
def <<(converter)
@converter = converter.respond_to?(:call) ? converter : converter.to_proc
self
end
|
275
276
277
|
# File 'lib/pattern-match/core.rb', line 275
def inspect
"#<#{self.class.name}: name=#{name.inspect}, val=#{@val.inspect}>"
end
|
#match(vals) ⇒ Object
236
237
238
239
240
241
|
# File 'lib/pattern-match/core.rb', line 236
def match(vals)
super do |val|
bind(val)
true
end
end
|
#set_bind_to(quantifier) ⇒ Object
247
248
249
250
251
252
253
254
255
256
257
258
259
|
# File 'lib/pattern-match/core.rb', line 247
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
261
262
263
264
265
266
267
268
269
270
271
272
273
|
# File 'lib/pattern-match/core.rb', line 261
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
|
243
244
245
|
# File 'lib/pattern-match/core.rb', line 243
def vars
[self]
end
|