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.



16969
16970
16971
16972
16973
16974
16975
# File 'lib/prism/node.rb', line 16969

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



17011
17012
17013
# File 'lib/prism/node.rb', line 17011

def body
  @body
end

Class Method Details

.typeObject

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



17024
17025
17026
# File 'lib/prism/node.rb', line 17024

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.



17030
17031
17032
17033
17034
# File 'lib/prism/node.rb', line 17030

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



16978
16979
16980
# File 'lib/prism/node.rb', line 16978

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



16983
16984
16985
# File 'lib/prism/node.rb', line 16983

def child_nodes
  [*body]
end

#comment_targetsObject

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



16993
16994
16995
# File 'lib/prism/node.rb', line 16993

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



16988
16989
16990
# File 'lib/prism/node.rb', line 16988

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



16998
16999
17000
# File 'lib/prism/node.rb', line 16998

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 }



17006
17007
17008
# File 'lib/prism/node.rb', line 17006

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

#inspectObject

def inspect -> String



17014
17015
17016
# File 'lib/prism/node.rb', line 17014

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



17019
17020
17021
# File 'lib/prism/node.rb', line 17019

def type
  :statements_node
end