Class: Patm::Pattern::Named
- Inherits:
-
Patm::Pattern
- Object
- Patm::Pattern
- Patm::Pattern::Named
- Defined in:
- lib/patm.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
(also: #index)
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #compile_internal(free_index, target_name = "_obj") ⇒ Object
- #execute(match, obj) ⇒ Object
-
#initialize(name) ⇒ Named
constructor
A new instance of Named.
- #inspect ⇒ Object
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.
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
#name ⇒ Object (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 |
#inspect ⇒ Object
428 |
# File 'lib/patm.rb', line 428 def inspect; "NAMED(#{@name})"; end |