Class: Prism::BeginNode
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
PrismNode
|
|
|
Instance Chain:
self,
PrismNode
|
|
| Inherits: |
PrismNode
|
| Defined in: | lib/prism/node.rb, ext/prism/api_node.c, lib/prism/parse_result/newlines.rb |
Overview
Represents a begin statement.
begin
foo
end
^^^^^
Class Method Summary
-
.new(source, node_id, location, flags, begin_keyword_loc, statements, rescue_clause, else_clause, ensure_clause, end_keyword_loc) ⇒ BeginNode
constructor
Initialize a new
BeginNodenode. -
.type
Return a symbol representation of this node type.
Instance Attribute Summary
-
#else_clause
readonly
attr_reader else_clause: ElseNode?
-
#ensure_clause
readonly
attr_reader ensure_clause: EnsureNode?
-
#rescue_clause
readonly
attr_reader rescue_clause: RescueNode?
-
#statements
readonly
attr_reader statements: StatementsNode?
Instance Method Summary
-
#===(other)
Implements case-equality for the node.
-
#accept(visitor)
def accept: (Visitor visitor) -> void.
-
#begin_keyword
def begin_keyword: () -> String?
-
#begin_keyword_loc
attr_reader begin_keyword_loc: Location?
-
#child_nodes
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes
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)
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
Alias for #child_nodes.
- #deconstruct_keys(keys)
-
#end_keyword
def end_keyword: () -> String?
-
#end_keyword_loc
attr_reader end_keyword_loc: Location?
-
#inspect
def inspect -> String.
-
#type
Return a symbol representation of this node type.
- #newline_flag!(lines) Internal use only
Constructor Details
.new(source, node_id, location, flags, begin_keyword_loc, statements, rescue_clause, else_clause, ensure_clause, end_keyword_loc) ⇒ BeginNode
Initialize a new BeginNode node.
# File 'lib/prism/node.rb', line 1255
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
Class Method Details
.type
Return a symbol representation of this node type. See Node::type.
# File 'lib/prism/node.rb', line 1361
def self.type :begin_node end
Instance Attribute Details
#else_clause (readonly)
attr_reader else_clause: ElseNode?
# File 'lib/prism/node.rb', line 1324
attr_reader :else_clause
#ensure_clause (readonly)
attr_reader ensure_clause: EnsureNode?
# File 'lib/prism/node.rb', line 1326
attr_reader :ensure_clause
#rescue_clause (readonly)
attr_reader rescue_clause: RescueNode?
# File 'lib/prism/node.rb', line 1322
attr_reader :rescue_clause
#statements (readonly)
attr_reader statements: StatementsNode?
# File 'lib/prism/node.rb', line 1320
attr_reader :statements
Instance Method Details
#===(other)
Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.
# File 'lib/prism/node.rb', line 1367
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)
def accept: (Visitor visitor) -> void
# File 'lib/prism/node.rb', line 1269
def accept(visitor) visitor.visit_begin_node(self) end
#begin_keyword
def begin_keyword: () -> String?
# File 'lib/prism/node.rb', line 1341
def begin_keyword begin_keyword_loc&.slice end
#begin_keyword_loc
attr_reader begin_keyword_loc: Location?
#child_nodes Also known as: #deconstruct
def child_nodes: () -> Array[nil | Node]
# File 'lib/prism/node.rb', line 1274
def child_nodes [statements, rescue_clause, else_clause, ensure_clause] end
#comment_targets
def comment_targets: () -> Array[Node | Location]
# File 'lib/prism/node.rb', line 1289
def comment_targets [*begin_keyword_loc, *statements, *rescue_clause, *else_clause, *ensure_clause, *end_keyword_loc] #: Array[Prism::node | Location] end
#compact_child_nodes
def compact_child_nodes: () -> Array
# File 'lib/prism/node.rb', line 1279
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)
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
# File 'lib/prism/node.rb', line 1294
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
Alias for #child_nodes.
# File 'lib/prism/node.rb', line 1299
alias deconstruct child_nodes
#deconstruct_keys(keys)
# File 'lib/prism/node.rb', line 1302
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
def end_keyword: () -> String?
# File 'lib/prism/node.rb', line 1346
def end_keyword end_keyword_loc&.slice end
#end_keyword_loc
attr_reader end_keyword_loc: Location?
#inspect
def inspect -> String
# File 'lib/prism/node.rb', line 1351
def inspect InspectVisitor.compose(self) end
#newline_flag!(lines)
# File 'lib/prism/parse_result/newlines.rb', line 80
def newline_flag!(lines) # :nodoc: # Never mark BeginNode with a newline flag, mark children instead. end
#type
Return a symbol representation of this node type. See Node#type.
# File 'lib/prism/node.rb', line 1356
def type :begin_node end