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.



2374
2375
2376
2377
2378
# File 'lib/syntax_tree/node.rb', line 2374

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



2369
2370
2371
# File 'lib/syntax_tree/node.rb', line 2369

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



2372
2373
2374
# File 'lib/syntax_tree/node.rb', line 2372

def comments
  @comments
end

Instance Method Details

#accept(visitor) ⇒ Object



2380
2381
2382
# File 'lib/syntax_tree/node.rb', line 2380

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

#child_nodesObject Also known as: deconstruct



2384
2385
2386
# File 'lib/syntax_tree/node.rb', line 2384

def child_nodes
  [arguments]
end

#deconstruct_keys(_keys) ⇒ Object



2390
2391
2392
# File 'lib/syntax_tree/node.rb', line 2390

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

#format(q) ⇒ Object



2394
2395
2396
# File 'lib/syntax_tree/node.rb', line 2394

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