Class: Prism::StatementsNode

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

Overview

Represents a set of statements contained within some scope.

foo; bar; baz
^^^^^^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, body) ⇒ StatementsNode

Initialize a new StatementsNode node.



16766
16767
16768
16769
16770
16771
16772
# File 'lib/prism/node.rb', line 16766

def initialize(source, node_id, location, flags, body)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

attr_reader body: Array



16808
16809
16810
# File 'lib/prism/node.rb', line 16808

def body
  @body
end

Class Method Details

.typeObject

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



16821
16822
16823
# File 'lib/prism/node.rb', line 16821

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



16827
16828
16829
16830
16831
# File 'lib/prism/node.rb', line 16827

def ===(other)
  other.is_a?(StatementsNode) &&
    (body.length == other.body.length) &&
    body.zip(other.body).all? { |left, right| left === right }
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



16775
16776
16777
# File 'lib/prism/node.rb', line 16775

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

#child_nodesObject Also known as: deconstruct

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



16780
16781
16782
# File 'lib/prism/node.rb', line 16780

def child_nodes
  [*body]
end

#comment_targetsObject

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



16790
16791
16792
# File 'lib/prism/node.rb', line 16790

def comment_targets
  [*body] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



16785
16786
16787
# File 'lib/prism/node.rb', line 16785

def compact_child_nodes
  [*body]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, body: self.body) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?body: Array) -> StatementsNode



16795
16796
16797
# File 'lib/prism/node.rb', line 16795

def copy(node_id: self.node_id, location: self.location, flags: self.flags, body: self.body)
  StatementsNode.new(source, node_id, location, flags, body)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, body: Array }



16803
16804
16805
# File 'lib/prism/node.rb', line 16803

def deconstruct_keys(keys)
  { node_id: node_id, location: location, body: body }
end

#inspectObject

def inspect -> String



16811
16812
16813
# File 'lib/prism/node.rb', line 16811

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



16816
16817
16818
# File 'lib/prism/node.rb', line 16816

def type
  :statements_node
end