Class: SyntaxTree::Yield0

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

Overview

Yield0 represents the bare yield keyword with no arguments.

yield

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Yield0.



11419
11420
11421
11422
11423
# File 'lib/syntax_tree/node.rb', line 11419

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



11417
11418
11419
# File 'lib/syntax_tree/node.rb', line 11417

def comments
  @comments
end

#valueObject (readonly)

String

the value of the keyword



11414
11415
11416
# File 'lib/syntax_tree/node.rb', line 11414

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



11425
11426
11427
# File 'lib/syntax_tree/node.rb', line 11425

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



11431
11432
11433
# File 'lib/syntax_tree/node.rb', line 11431

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

#format(q) ⇒ Object



11435
11436
11437
# File 'lib/syntax_tree/node.rb', line 11435

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

#pretty_print(q) ⇒ Object



11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
# File 'lib/syntax_tree/node.rb', line 11439

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

    q.breakable
    q.pp(value)

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

#to_json(*opts) ⇒ Object



11450
11451
11452
11453
11454
# File 'lib/syntax_tree/node.rb', line 11450

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