Class: Patm::Pattern::Named

Inherits:
Patm::Pattern show all
Defined in:
lib/patm.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Patm::Pattern

#&, #[], build_from, #compile, #opt, #opt?, #rest?

Constructor Details

#initialize(name) ⇒ Named

Returns a new instance of Named.

Raises:

  • (::ArgumentError)


327
328
329
330
# File 'lib/patm.rb', line 327

def initialize(name)
  raise ::ArgumentError unless name.is_a?(Symbol) || name.is_a?(Numeric)
  @name = name
end

Instance Attribute Details

#nameObject (readonly) Also known as: index

Returns the value of attribute name.



331
332
333
# File 'lib/patm.rb', line 331

def name
  @name
end

Instance Method Details

#compile_internal(free_index, target_name = "_obj") ⇒ Object



338
339
340
341
342
343
344
# File 'lib/patm.rb', line 338

def compile_internal(free_index, target_name = "_obj")
  [
    "_match[#{@name.inspect}] = #{target_name}; true",
    [],
    free_index
  ]
end

#execute(match, obj) ⇒ Object



333
334
335
336
# File 'lib/patm.rb', line 333

def execute(match, obj)
  match[@name] = obj
  true
end

#inspectObject



337
# File 'lib/patm.rb', line 337

def inspect; "NAMED(#{@name})"; end