Class: SyntaxTree::Yield0

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

Overview

Yield0 represents the bare yield keyword with no arguments.

yield

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Yield0.



13618
13619
13620
13621
13622
# File 'lib/syntax_tree.rb', line 13618

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



13616
13617
13618
# File 'lib/syntax_tree.rb', line 13616

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



13613
13614
13615
# File 'lib/syntax_tree.rb', line 13613

def location
  @location
end

#valueObject (readonly)

String

the value of the keyword



13610
13611
13612
# File 'lib/syntax_tree.rb', line 13610

def value
  @value
end

Instance Method Details

#child_nodesObject



13624
13625
13626
# File 'lib/syntax_tree.rb', line 13624

def child_nodes
  []
end

#format(q) ⇒ Object



13628
13629
13630
# File 'lib/syntax_tree.rb', line 13628

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

#pretty_print(q) ⇒ Object



13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
# File 'lib/syntax_tree.rb', line 13632

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



13643
13644
13645
13646
13647
# File 'lib/syntax_tree.rb', line 13643

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