Class: Prism::EmbeddedStatementsNode

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

Overview

Represents an interpolated set of statements.

"foo #{bar}"
     ^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, opening_loc, statements, closing_loc) ⇒ EmbeddedStatementsNode

Initialize a new EmbeddedStatementsNode node.



5596
5597
5598
5599
5600
5601
5602
5603
5604
# File 'lib/prism/node.rb', line 5596

def initialize(source, node_id, location, flags, opening_loc, statements, closing_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @opening_loc = opening_loc
  @statements = statements
  @closing_loc = closing_loc
end

Instance Attribute Details

#statementsObject (readonly)

attr_reader statements: StatementsNode?



5649
5650
5651
# File 'lib/prism/node.rb', line 5649

def statements
  @statements
end

Class Method Details

.typeObject

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



5679
5680
5681
# File 'lib/prism/node.rb', line 5679

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



5685
5686
5687
5688
5689
5690
# File 'lib/prism/node.rb', line 5685

def ===(other)
  other.is_a?(EmbeddedStatementsNode) &&
    (opening_loc.nil? == other.opening_loc.nil?) &&
    (statements === other.statements) &&
    (closing_loc.nil? == other.closing_loc.nil?)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



5607
5608
5609
# File 'lib/prism/node.rb', line 5607

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

#child_nodesObject Also known as: deconstruct

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



5612
5613
5614
# File 'lib/prism/node.rb', line 5612

def child_nodes
  [statements]
end

#closingObject

def closing: () -> String



5664
5665
5666
# File 'lib/prism/node.rb', line 5664

def closing
  closing_loc.slice
end

#closing_locObject

attr_reader closing_loc: Location



5652
5653
5654
5655
5656
# File 'lib/prism/node.rb', line 5652

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

#comment_targetsObject

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



5624
5625
5626
# File 'lib/prism/node.rb', line 5624

def comment_targets
  [opening_loc, *statements, closing_loc] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



5617
5618
5619
5620
5621
# File 'lib/prism/node.rb', line 5617

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact << statements if statements
  compact
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, statements: self.statements, closing_loc: self.closing_loc) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location, ?statements: StatementsNode?, ?closing_loc: Location) -> EmbeddedStatementsNode



5629
5630
5631
# File 'lib/prism/node.rb', line 5629

def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, statements: self.statements, closing_loc: self.closing_loc)
  EmbeddedStatementsNode.new(source, node_id, location, flags, opening_loc, statements, closing_loc)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, opening_loc: Location, statements: StatementsNode?, closing_loc: Location }



5637
5638
5639
# File 'lib/prism/node.rb', line 5637

def deconstruct_keys(keys)
  { node_id: node_id, location: location, opening_loc: opening_loc, statements: statements, closing_loc: closing_loc }
end

#inspectObject

def inspect -> String



5669
5670
5671
# File 'lib/prism/node.rb', line 5669

def inspect
  InspectVisitor.compose(self)
end

#openingObject

def opening: () -> String



5659
5660
5661
# File 'lib/prism/node.rb', line 5659

def opening
  opening_loc.slice
end

#opening_locObject

attr_reader opening_loc: Location



5642
5643
5644
5645
5646
# File 'lib/prism/node.rb', line 5642

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

#typeObject

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



5674
5675
5676
# File 'lib/prism/node.rb', line 5674

def type
  :embedded_statements_node
end