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

#construct_keys, #pretty_print, #to_json

Constructor Details

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

Returns a new instance of Break.



2311
2312
2313
2314
2315
# File 'lib/syntax_tree/node.rb', line 2311

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



2306
2307
2308
# File 'lib/syntax_tree/node.rb', line 2306

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



2309
2310
2311
# File 'lib/syntax_tree/node.rb', line 2309

def comments
  @comments
end

Instance Method Details

#accept(visitor) ⇒ Object



2317
2318
2319
# File 'lib/syntax_tree/node.rb', line 2317

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

#child_nodesObject Also known as: deconstruct



2321
2322
2323
# File 'lib/syntax_tree/node.rb', line 2321

def child_nodes
  [arguments]
end

#deconstruct_keys(_keys) ⇒ Object



2327
2328
2329
# File 'lib/syntax_tree/node.rb', line 2327

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

#format(q) ⇒ Object



2331
2332
2333
# File 'lib/syntax_tree/node.rb', line 2331

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