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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Redo.



8519
8520
8521
8522
8523
# File 'lib/syntax_tree/node.rb', line 8519

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



8517
8518
8519
# File 'lib/syntax_tree/node.rb', line 8517

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



8514
8515
8516
# File 'lib/syntax_tree/node.rb', line 8514

def location
  @location
end

#valueObject (readonly)

String

the value of the keyword



8511
8512
8513
# File 'lib/syntax_tree/node.rb', line 8511

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



8525
8526
8527
# File 'lib/syntax_tree/node.rb', line 8525

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



8531
8532
8533
# File 'lib/syntax_tree/node.rb', line 8531

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

#format(q) ⇒ Object



8535
8536
8537
# File 'lib/syntax_tree/node.rb', line 8535

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

#pretty_print(q) ⇒ Object



8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
# File 'lib/syntax_tree/node.rb', line 8539

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



8550
8551
8552
8553
8554
# File 'lib/syntax_tree/node.rb', line 8550

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