class SyntaxTree::Begin

Begin represents a begin..end chain.

begin
  value
end

Attributes

bodystmt[R]
BodyStmt

the bodystmt that contains the contents of this begin block

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

Public Class Methods

new(bodystmt:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 1906
def initialize(bodystmt:, location:)
  @bodystmt = bodystmt
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 1951
def ===(other)
  other.is_a?(Begin) && bodystmt === other.bodystmt
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 1912
def accept(visitor)
  visitor.visit_begin(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 1916
def child_nodes
  [bodystmt]
end
Also aliased as: deconstruct
copy(bodystmt: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 1920
def copy(bodystmt: nil, location: nil)
  node =
    Begin.new(
      bodystmt: bodystmt || self.bodystmt,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end
deconstruct()
Alias for: child_nodes
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/node.rb, line 1933
def deconstruct_keys(_keys)
  { bodystmt: bodystmt, location: location, comments: comments }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 1937
def format(q)
  q.text("begin")

  unless bodystmt.empty?
    q.indent do
      q.breakable_force unless bodystmt.statements.empty?
      q.format(bodystmt)
    end
  end

  q.breakable_force
  q.text("end")
end