Class: Prism::MatchRequiredNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
ext/prism/api_node.c

Overview

Represents the use of the ‘=>` operator.

foo => bar
^^^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, value, pattern, operator_loc) ⇒ MatchRequiredNode

Initialize a new MatchRequiredNode node.



11312
11313
11314
11315
11316
11317
11318
11319
11320
# File 'lib/prism/node.rb', line 11312

def initialize(source, node_id, location, flags, value, pattern, operator_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @value = value
  @pattern = pattern
  @operator_loc = operator_loc
end

Instance Attribute Details

#patternObject (readonly)

attr_reader pattern: Prism::node



11359
11360
11361
# File 'lib/prism/node.rb', line 11359

def pattern
  @pattern
end

#valueObject (readonly)

attr_reader value: Prism::node



11356
11357
11358
# File 'lib/prism/node.rb', line 11356

def value
  @value
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



11384
11385
11386
# File 'lib/prism/node.rb', line 11384

def self.type
  :match_required_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



11390
11391
11392
11393
11394
11395
# File 'lib/prism/node.rb', line 11390

def ===(other)
  other.is_a?(MatchRequiredNode) &&
    (value === other.value) &&
    (pattern === other.pattern) &&
    (operator_loc.nil? == other.operator_loc.nil?)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



11323
11324
11325
# File 'lib/prism/node.rb', line 11323

def accept(visitor)
  visitor.visit_match_required_node(self)
end

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



11328
11329
11330
# File 'lib/prism/node.rb', line 11328

def child_nodes
  [value, pattern]
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



11338
11339
11340
# File 'lib/prism/node.rb', line 11338

def comment_targets
  [value, pattern, operator_loc] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



11333
11334
11335
# File 'lib/prism/node.rb', line 11333

def compact_child_nodes
  [value, pattern]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, pattern: self.pattern, operator_loc: self.operator_loc) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?value: Prism::node, ?pattern: Prism::node, ?operator_loc: Location) -> MatchRequiredNode



11343
11344
11345
# File 'lib/prism/node.rb', line 11343

def copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, pattern: self.pattern, operator_loc: self.operator_loc)
  MatchRequiredNode.new(source, node_id, location, flags, value, pattern, operator_loc)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, value: Prism::node, pattern: Prism::node, operator_loc: Location }



11351
11352
11353
# File 'lib/prism/node.rb', line 11351

def deconstruct_keys(keys)
  { node_id: node_id, location: location, value: value, pattern: pattern, operator_loc: operator_loc }
end

#inspectObject

def inspect -> String



11374
11375
11376
# File 'lib/prism/node.rb', line 11374

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



11369
11370
11371
# File 'lib/prism/node.rb', line 11369

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



11362
11363
11364
11365
11366
# File 'lib/prism/node.rb', line 11362

def operator_loc
  location = @operator_loc
  return location if location.is_a?(Location)
  @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



11379
11380
11381
# File 'lib/prism/node.rb', line 11379

def type
  :match_required_node
end