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.



3232
3233
3234
3235
3236
# File 'lib/syntax_tree.rb', line 3232

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



3224
3225
3226
# File 'lib/syntax_tree.rb', line 3224

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



3230
3231
3232
# File 'lib/syntax_tree.rb', line 3230

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



3227
3228
3229
# File 'lib/syntax_tree.rb', line 3227

def location
  @location
end

Instance Method Details

#child_nodesObject



3238
3239
3240
# File 'lib/syntax_tree.rb', line 3238

def child_nodes
  [arguments]
end

#format(q) ⇒ Object



3242
3243
3244
# File 'lib/syntax_tree.rb', line 3242

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

#pretty_print(q) ⇒ Object



3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
# File 'lib/syntax_tree.rb', line 3246

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



3257
3258
3259
3260
3261
# File 'lib/syntax_tree.rb', line 3257

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