Class: Prism::BeginNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::BeginNode
- Defined in:
- lib/prism/node.rb,
lib/prism/parse_result/newlines.rb,
ext/prism/api_node.c
Overview
Represents a begin statement.
begin
foo
end
^^^^^
Instance Attribute Summary collapse
-
#else_clause ⇒ Object
readonly
attr_reader else_clause: ElseNode?.
-
#ensure_clause ⇒ Object
readonly
attr_reader ensure_clause: EnsureNode?.
-
#rescue_clause ⇒ Object
readonly
attr_reader rescue_clause: RescueNode?.
-
#statements ⇒ Object
readonly
attr_reader statements: StatementsNode?.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#begin_keyword ⇒ Object
def begin_keyword: () -> String?.
-
#begin_keyword_loc ⇒ Object
attr_reader begin_keyword_loc: Location?.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, begin_keyword_loc: self.begin_keyword_loc, statements: self.statements, rescue_clause: self.rescue_clause, else_clause: self.else_clause, ensure_clause: self.ensure_clause, end_keyword_loc: self.end_keyword_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?begin_keyword_loc: Location?, ?statements: StatementsNode?, ?rescue_clause: RescueNode?, ?else_clause: ElseNode?, ?ensure_clause: EnsureNode?, ?end_keyword_loc: Location?) -> BeginNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, begin_keyword_loc: Location?, statements: StatementsNode?, rescue_clause: RescueNode?, else_clause: ElseNode?, ensure_clause: EnsureNode?, end_keyword_loc: Location? }.
-
#end_keyword ⇒ Object
def end_keyword: () -> String?.
-
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location?.
-
#initialize(source, node_id, location, flags, begin_keyword_loc, statements, rescue_clause, else_clause, ensure_clause, end_keyword_loc) ⇒ BeginNode
constructor
Initialize a new BeginNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#newline_flag!(lines) ⇒ Object
:nodoc:.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, begin_keyword_loc, statements, rescue_clause, else_clause, ensure_clause, end_keyword_loc) ⇒ BeginNode
Initialize a new BeginNode node.
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 |
# File 'lib/prism/node.rb', line 1278 def initialize(source, node_id, location, flags, begin_keyword_loc, statements, rescue_clause, else_clause, ensure_clause, end_keyword_loc) @source = source @node_id = node_id @location = location @flags = flags @begin_keyword_loc = begin_keyword_loc @statements = statements @rescue_clause = rescue_clause @else_clause = else_clause @ensure_clause = ensure_clause @end_keyword_loc = end_keyword_loc end |
Instance Attribute Details
#else_clause ⇒ Object (readonly)
attr_reader else_clause: ElseNode?
1349 1350 1351 |
# File 'lib/prism/node.rb', line 1349 def else_clause @else_clause end |
#ensure_clause ⇒ Object (readonly)
attr_reader ensure_clause: EnsureNode?
1352 1353 1354 |
# File 'lib/prism/node.rb', line 1352 def ensure_clause @ensure_clause end |
#rescue_clause ⇒ Object (readonly)
attr_reader rescue_clause: RescueNode?
1346 1347 1348 |
# File 'lib/prism/node.rb', line 1346 def rescue_clause @rescue_clause end |
#statements ⇒ Object (readonly)
attr_reader statements: StatementsNode?
1343 1344 1345 |
# File 'lib/prism/node.rb', line 1343 def statements @statements end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
1388 1389 1390 |
# File 'lib/prism/node.rb', line 1388 def self.type :begin_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.
1394 1395 1396 1397 1398 1399 1400 1401 1402 |
# File 'lib/prism/node.rb', line 1394 def ===(other) other.is_a?(BeginNode) && (begin_keyword_loc.nil? == other.begin_keyword_loc.nil?) && (statements === other.statements) && (rescue_clause === other.rescue_clause) && (else_clause === other.else_clause) && (ensure_clause === other.ensure_clause) && (end_keyword_loc.nil? == other.end_keyword_loc.nil?) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
1292 1293 1294 |
# File 'lib/prism/node.rb', line 1292 def accept(visitor) visitor.visit_begin_node(self) end |
#begin_keyword ⇒ Object
def begin_keyword: () -> String?
1368 1369 1370 |
# File 'lib/prism/node.rb', line 1368 def begin_keyword begin_keyword_loc&.slice end |
#begin_keyword_loc ⇒ Object
attr_reader begin_keyword_loc: Location?
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 |
# File 'lib/prism/node.rb', line 1330 def begin_keyword_loc location = @begin_keyword_loc case location when nil nil when Location location else @begin_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
1297 1298 1299 |
# File 'lib/prism/node.rb', line 1297 def child_nodes [statements, rescue_clause, else_clause, ensure_clause] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
1312 1313 1314 |
# File 'lib/prism/node.rb', line 1312 def comment_targets [*begin_keyword_loc, *statements, *rescue_clause, *else_clause, *ensure_clause, *end_keyword_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
1302 1303 1304 1305 1306 1307 1308 1309 |
# File 'lib/prism/node.rb', line 1302 def compact_child_nodes compact = [] #: Array[Prism::node] compact << statements if statements compact << rescue_clause if rescue_clause compact << else_clause if else_clause compact << ensure_clause if ensure_clause compact end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, begin_keyword_loc: self.begin_keyword_loc, statements: self.statements, rescue_clause: self.rescue_clause, else_clause: self.else_clause, ensure_clause: self.ensure_clause, end_keyword_loc: self.end_keyword_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?begin_keyword_loc: Location?, ?statements: StatementsNode?, ?rescue_clause: RescueNode?, ?else_clause: ElseNode?, ?ensure_clause: EnsureNode?, ?end_keyword_loc: Location?) -> BeginNode
1317 1318 1319 |
# File 'lib/prism/node.rb', line 1317 def copy(node_id: self.node_id, location: self.location, flags: self.flags, begin_keyword_loc: self.begin_keyword_loc, statements: self.statements, rescue_clause: self.rescue_clause, else_clause: self.else_clause, ensure_clause: self.ensure_clause, end_keyword_loc: self.end_keyword_loc) BeginNode.new(source, node_id, location, flags, begin_keyword_loc, statements, rescue_clause, else_clause, ensure_clause, end_keyword_loc) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, begin_keyword_loc: Location?, statements: StatementsNode?, rescue_clause: RescueNode?, else_clause: ElseNode?, ensure_clause: EnsureNode?, end_keyword_loc: Location? }
1325 1326 1327 |
# File 'lib/prism/node.rb', line 1325 def deconstruct_keys(keys) { node_id: node_id, location: location, begin_keyword_loc: begin_keyword_loc, statements: statements, rescue_clause: rescue_clause, else_clause: else_clause, ensure_clause: ensure_clause, end_keyword_loc: end_keyword_loc } end |
#end_keyword ⇒ Object
def end_keyword: () -> String?
1373 1374 1375 |
# File 'lib/prism/node.rb', line 1373 def end_keyword end_keyword_loc&.slice end |
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location?
1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 |
# File 'lib/prism/node.rb', line 1355 def end_keyword_loc location = @end_keyword_loc case location when nil nil when Location location else @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#inspect ⇒ Object
def inspect -> String
1378 1379 1380 |
# File 'lib/prism/node.rb', line 1378 def inspect InspectVisitor.compose(self) end |
#newline_flag!(lines) ⇒ Object
:nodoc:
79 80 81 |
# File 'lib/prism/parse_result/newlines.rb', line 79 def newline_flag!(lines) # :nodoc: # Never mark BeginNode with a newline flag, mark children instead. end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
1383 1384 1385 |
# File 'lib/prism/node.rb', line 1383 def type :begin_node end |