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, build_from_array, build_from_hash, #compile, #opt, #opt?, #rest?

Constructor Details

#initialize(name) ⇒ Named

Returns a new instance of Named.

Raises:

  • (::ArgumentError)


418
419
420
421
# File 'lib/patm.rb', line 418

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.



422
423
424
# File 'lib/patm.rb', line 422

def name
  @name
end

Instance Method Details

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



429
430
431
432
433
434
435
# File 'lib/patm.rb', line 429

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

#execute(match, obj) ⇒ Object



424
425
426
427
# File 'lib/patm.rb', line 424

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

#inspectObject



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

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