Class: Prism::MatchPredicateNode

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

Overview

Represents the use of the modifier ‘in` operator.

foo in 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) ⇒ MatchPredicateNode

Initialize a new MatchPredicateNode node.



12682
12683
12684
12685
12686
12687
12688
12689
12690
# File 'lib/prism/node.rb', line 12682

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



12729
12730
12731
# File 'lib/prism/node.rb', line 12729

def pattern
  @pattern
end

#valueObject (readonly)

attr_reader value: Prism::node



12726
12727
12728
# File 'lib/prism/node.rb', line 12726

def value
  @value
end

Class Method Details

.typeObject

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



12760
12761
12762
# File 'lib/prism/node.rb', line 12760

def self.type
  :match_predicate_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.



12766
12767
12768
12769
12770
12771
# File 'lib/prism/node.rb', line 12766

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

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



12693
12694
12695
# File 'lib/prism/node.rb', line 12693

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



12698
12699
12700
# File 'lib/prism/node.rb', line 12698

def child_nodes
  [value, pattern]
end

#comment_targetsObject

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



12708
12709
12710
# File 'lib/prism/node.rb', line 12708

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



12703
12704
12705
# File 'lib/prism/node.rb', line 12703

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) -> MatchPredicateNode



12713
12714
12715
# File 'lib/prism/node.rb', line 12713

def copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, pattern: self.pattern, operator_loc: self.operator_loc)
  MatchPredicateNode.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 }



12721
12722
12723
# File 'lib/prism/node.rb', line 12721

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

#inspectObject

def inspect -> String



12750
12751
12752
# File 'lib/prism/node.rb', line 12750

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



12745
12746
12747
# File 'lib/prism/node.rb', line 12745

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



12732
12733
12734
12735
12736
# File 'lib/prism/node.rb', line 12732

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

#save_operator_loc(repository) ⇒ Object

Save the operator_loc location using the given saved source so that it can be retrieved later.



12740
12741
12742
# File 'lib/prism/node.rb', line 12740

def save_operator_loc(repository)
  repository.enter(node_id, :operator_loc)
end

#typeObject

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



12755
12756
12757
# File 'lib/prism/node.rb', line 12755

def type
  :match_predicate_node
end