Class: SyntaxTree::Break

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

Break represents using the break keyword.

break

It can also optionally accept arguments, as in:

break 1

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

#initialize(arguments:, location:, comments: []) ⇒ Break

Returns a new instance of Break.



2096
2097
2098
2099
2100
# File 'lib/syntax_tree/node.rb', line 2096

def initialize(arguments:, location:, comments: [])
  @arguments = arguments
  @location = location
  @comments = comments
end

Instance Attribute Details

#argumentsObject (readonly)

Args

the arguments being sent to the keyword



2091
2092
2093
# File 'lib/syntax_tree/node.rb', line 2091

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



2094
2095
2096
# File 'lib/syntax_tree/node.rb', line 2094

def comments
  @comments
end

Instance Method Details

#accept(visitor) ⇒ Object



2102
2103
2104
# File 'lib/syntax_tree/node.rb', line 2102

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

#child_nodesObject Also known as: deconstruct



2106
2107
2108
# File 'lib/syntax_tree/node.rb', line 2106

def child_nodes
  [arguments]
end

#deconstruct_keys(keys) ⇒ Object



2112
2113
2114
# File 'lib/syntax_tree/node.rb', line 2112

def deconstruct_keys(keys)
  { arguments: arguments, location: location, comments: comments }
end

#format(q) ⇒ Object



2116
2117
2118
# File 'lib/syntax_tree/node.rb', line 2116

def format(q)
  FlowControlFormatter.new("break", self).format(q)
end