Class: SyntaxTree::Break

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

Overview

Break represents using the break keyword.

break

It can also optionally accept arguments, as in:

break 1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Break.



2883
2884
2885
2886
2887
# File 'lib/syntax_tree.rb', line 2883

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



2875
2876
2877
# File 'lib/syntax_tree.rb', line 2875

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



2881
2882
2883
# File 'lib/syntax_tree.rb', line 2881

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



2878
2879
2880
# File 'lib/syntax_tree.rb', line 2878

def location
  @location
end

Instance Method Details

#child_nodesObject



2889
2890
2891
# File 'lib/syntax_tree.rb', line 2889

def child_nodes
  [arguments]
end

#format(q) ⇒ Object



2893
2894
2895
# File 'lib/syntax_tree.rb', line 2893

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

#pretty_print(q) ⇒ Object



2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
# File 'lib/syntax_tree.rb', line 2897

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



2908
2909
2910
2911
2912
# File 'lib/syntax_tree.rb', line 2908

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