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.



13098
13099
13100
13101
13102
# File 'lib/syntax_tree.rb', line 13098

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



13096
13097
13098
# File 'lib/syntax_tree.rb', line 13096

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



13093
13094
13095
# File 'lib/syntax_tree.rb', line 13093

def location
  @location
end

#valueObject (readonly)

String

the value of the keyword



13090
13091
13092
# File 'lib/syntax_tree.rb', line 13090

def value
  @value
end

Instance Method Details

#child_nodesObject



13104
13105
13106
# File 'lib/syntax_tree.rb', line 13104

def child_nodes
  []
end

#format(q) ⇒ Object



13108
13109
13110
# File 'lib/syntax_tree.rb', line 13108

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

#pretty_print(q) ⇒ Object



13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
# File 'lib/syntax_tree.rb', line 13112

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



13123
13124
13125
13126
13127
# File 'lib/syntax_tree.rb', line 13123

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