Class: SyntaxTree::Return

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

Overview

Return represents using the return keyword with arguments.

return value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments:, location:, comments: []) ⇒ Return

Returns a new instance of Return.



9161
9162
9163
9164
9165
# File 'lib/syntax_tree/node.rb', line 9161

def initialize(arguments:, location:, comments: [])
  @arguments = arguments
  @location = location
  @comments = comments
end

Instance Attribute Details

#argumentsObject (readonly)

Args

the arguments being passed to the keyword



9153
9154
9155
# File 'lib/syntax_tree/node.rb', line 9153

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



9159
9160
9161
# File 'lib/syntax_tree/node.rb', line 9159

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



9156
9157
9158
# File 'lib/syntax_tree/node.rb', line 9156

def location
  @location
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



9167
9168
9169
# File 'lib/syntax_tree/node.rb', line 9167

def child_nodes
  [arguments]
end

#deconstruct_keys(keys) ⇒ Object



9173
9174
9175
# File 'lib/syntax_tree/node.rb', line 9173

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

#format(q) ⇒ Object



9177
9178
9179
# File 'lib/syntax_tree/node.rb', line 9177

def format(q)
  FlowControlFormatter.new("return", self).format(q)
end

#pretty_print(q) ⇒ Object



9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
# File 'lib/syntax_tree/node.rb', line 9181

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

    q.breakable
    q.pp(arguments)

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

#to_json(*opts) ⇒ Object



9192
9193
9194
9195
9196
# File 'lib/syntax_tree/node.rb', line 9192

def to_json(*opts)
  { type: :return, args: arguments, loc: location, cmts: comments }.to_json(
    *opts
  )
end