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)


312
313
314
315
# File 'lib/patm.rb', line 312

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.



316
317
318
# File 'lib/patm.rb', line 316

def name
  @name
end

Instance Method Details

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



323
324
325
326
327
328
329
# File 'lib/patm.rb', line 323

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

#execute(match, obj) ⇒ Object



318
319
320
321
# File 'lib/patm.rb', line 318

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

#inspectObject



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

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