Class: YARP::StatementsNode

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

Overview

Represents a set of statements contained within some scope.

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, location) ⇒ StatementsNode

def initialize: (body: Array, location: Location) -> void



9498
9499
9500
9501
# File 'lib/yarp/node.rb', line 9498

def initialize(body, location)
  @body = body
  @location = location
end

Instance Attribute Details

#bodyObject (readonly)

attr_reader body: Array



9495
9496
9497
# File 'lib/yarp/node.rb', line 9495

def body
  @body
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



9504
9505
9506
# File 'lib/yarp/node.rb', line 9504

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

#child_nodesObject Also known as: deconstruct

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



9509
9510
9511
# File 'lib/yarp/node.rb', line 9509

def child_nodes
  [*body]
end

#comment_targetsObject

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



9514
9515
9516
# File 'lib/yarp/node.rb', line 9514

def comment_targets
  [*body]
end

#copy(**params) ⇒ Object

def copy: (**params) -> StatementsNode



9519
9520
9521
9522
9523
9524
# File 'lib/yarp/node.rb', line 9519

def copy(**params)
  StatementsNode.new(
    params.fetch(:body) { body },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



9530
9531
9532
# File 'lib/yarp/node.rb', line 9530

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

#inspect(inspector = NodeInspector.new) ⇒ Object



9534
9535
9536
9537
9538
# File 'lib/yarp/node.rb', line 9534

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  inspector << "└── body: #{inspector.list("#{inspector.prefix}    ", body)}"
  inspector.to_str
end