Class: SyntaxTree::Redo

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

Overview

Redo represents the use of the redo keyword.

redo

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Constructor Details

#initialize(value:, location:, comments: []) ⇒ Redo

Returns a new instance of Redo.



8210
8211
8212
8213
8214
# File 'lib/syntax_tree/node.rb', line 8210

def initialize(value:, location:, comments: [])
  @value = value
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8208
8209
8210
# File 'lib/syntax_tree/node.rb', line 8208

def comments
  @comments
end

#valueObject (readonly)

String

the value of the keyword



8205
8206
8207
# File 'lib/syntax_tree/node.rb', line 8205

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



8216
8217
8218
# File 'lib/syntax_tree/node.rb', line 8216

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



8222
8223
8224
# File 'lib/syntax_tree/node.rb', line 8222

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

#format(q) ⇒ Object



8226
8227
8228
# File 'lib/syntax_tree/node.rb', line 8226

def format(q)
  q.text(value)
end

#pretty_print(q) ⇒ Object



8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
# File 'lib/syntax_tree/node.rb', line 8230

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

    q.breakable
    q.pp(value)

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

#to_json(*opts) ⇒ Object



8241
8242
8243
8244
8245
# File 'lib/syntax_tree/node.rb', line 8241

def to_json(*opts)
  { type: :redo, value: value, loc: location, cmts: comments }.to_json(
    *opts
  )
end