Class: SyntaxTree::Return0

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

Overview

Return0 represents the bare return keyword with no arguments.

return

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Return0.



10128
10129
10130
10131
10132
# File 'lib/syntax_tree.rb', line 10128

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



10126
10127
10128
# File 'lib/syntax_tree.rb', line 10126

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



10123
10124
10125
# File 'lib/syntax_tree.rb', line 10123

def location
  @location
end

#valueObject (readonly)

String

the value of the keyword



10120
10121
10122
# File 'lib/syntax_tree.rb', line 10120

def value
  @value
end

Instance Method Details

#child_nodesObject



10134
10135
10136
# File 'lib/syntax_tree.rb', line 10134

def child_nodes
  []
end

#format(q) ⇒ Object



10138
10139
10140
# File 'lib/syntax_tree.rb', line 10138

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

#pretty_print(q) ⇒ Object



10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
# File 'lib/syntax_tree.rb', line 10142

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

    q.breakable
    q.pp(value)

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

#to_json(*opts) ⇒ Object



10153
10154
10155
10156
10157
# File 'lib/syntax_tree.rb', line 10153

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