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.



18031
18032
18033
18034
18035
18036
18037
# File 'lib/prism/node.rb', line 18031

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



18080
18081
18082
# File 'lib/prism/node.rb', line 18080

def body
  @body
end

Class Method Details

.typeObject

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



18093
18094
18095
# File 'lib/prism/node.rb', line 18093

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.



18099
18100
18101
18102
18103
# File 'lib/prism/node.rb', line 18099

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



18040
18041
18042
# File 'lib/prism/node.rb', line 18040

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



18045
18046
18047
# File 'lib/prism/node.rb', line 18045

def child_nodes
  [*body]
end

#comment_targetsObject

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



18062
18063
18064
# File 'lib/prism/node.rb', line 18062

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



18057
18058
18059
# File 'lib/prism/node.rb', line 18057

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



18067
18068
18069
# File 'lib/prism/node.rb', line 18067

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 }



18075
18076
18077
# File 'lib/prism/node.rb', line 18075

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

#each_child_nodeObject

def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator



18050
18051
18052
18053
18054
# File 'lib/prism/node.rb', line 18050

def each_child_node
  return to_enum(:each_child_node) unless block_given?

  body.each { |node| yield node }
end

#inspectObject

def inspect -> String



18083
18084
18085
# File 'lib/prism/node.rb', line 18083

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



18088
18089
18090
# File 'lib/prism/node.rb', line 18088

def type
  :statements_node
end