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.



3111
3112
3113
3114
3115
# File 'lib/syntax_tree.rb', line 3111

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



3103
3104
3105
# File 'lib/syntax_tree.rb', line 3103

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



3109
3110
3111
# File 'lib/syntax_tree.rb', line 3109

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



3106
3107
3108
# File 'lib/syntax_tree.rb', line 3106

def location
  @location
end

Instance Method Details

#child_nodesObject



3117
3118
3119
# File 'lib/syntax_tree.rb', line 3117

def child_nodes
  [arguments]
end

#format(q) ⇒ Object



3121
3122
3123
# File 'lib/syntax_tree.rb', line 3121

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

#pretty_print(q) ⇒ Object



3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
# File 'lib/syntax_tree.rb', line 3125

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



3136
3137
3138
3139
3140
# File 'lib/syntax_tree.rb', line 3136

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