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.



15225
15226
15227
15228
15229
15230
15231
# File 'lib/prism/node.rb', line 15225

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



15267
15268
15269
# File 'lib/prism/node.rb', line 15267

def body
  @body
end

Class Method Details

.typeObject

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



15280
15281
15282
# File 'lib/prism/node.rb', line 15280

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.



15286
15287
15288
15289
15290
# File 'lib/prism/node.rb', line 15286

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



15234
15235
15236
# File 'lib/prism/node.rb', line 15234

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

#child_nodesObject Also known as: deconstruct

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



15239
15240
15241
# File 'lib/prism/node.rb', line 15239

def child_nodes
  [*body]
end

#comment_targetsObject

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



15249
15250
15251
# File 'lib/prism/node.rb', line 15249

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



15244
15245
15246
# File 'lib/prism/node.rb', line 15244

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



15254
15255
15256
# File 'lib/prism/node.rb', line 15254

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 }



15262
15263
15264
# File 'lib/prism/node.rb', line 15262

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

#inspectObject

def inspect -> String



15270
15271
15272
# File 'lib/prism/node.rb', line 15270

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



15275
15276
15277
# File 'lib/prism/node.rb', line 15275

def type
  :statements_node
end