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

Constructor Details

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

Returns a new instance of Break.



2564
2565
2566
2567
2568
# File 'lib/syntax_tree/node.rb', line 2564

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



2559
2560
2561
# File 'lib/syntax_tree/node.rb', line 2559

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



2562
2563
2564
# File 'lib/syntax_tree/node.rb', line 2562

def comments
  @comments
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



2570
2571
2572
# File 'lib/syntax_tree/node.rb', line 2570

def child_nodes
  [arguments]
end

#deconstruct_keys(keys) ⇒ Object



2576
2577
2578
# File 'lib/syntax_tree/node.rb', line 2576

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

#format(q) ⇒ Object



2580
2581
2582
# File 'lib/syntax_tree/node.rb', line 2580

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

#pretty_print(q) ⇒ Object



2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
# File 'lib/syntax_tree/node.rb', line 2584

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("break")

    q.breakable
    q.pp(arguments)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



2595
2596
2597
2598
2599
# File 'lib/syntax_tree/node.rb', line 2595

def to_json(*opts)
  { type: :break, args: arguments, loc: location, cmts: comments }.to_json(
    *opts
  )
end