Class: SyntaxTree::ArgStar

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

Overview

Star represents using a splat operator on an expression.

method(*arguments)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ArgStar.



1239
1240
1241
1242
1243
# File 'lib/syntax_tree.rb', line 1239

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



1237
1238
1239
# File 'lib/syntax_tree.rb', line 1237

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



1234
1235
1236
# File 'lib/syntax_tree.rb', line 1234

def location
  @location
end

#valueObject (readonly)

nil | untyped

the expression being splatted



1231
1232
1233
# File 'lib/syntax_tree.rb', line 1231

def value
  @value
end

Instance Method Details

#child_nodesObject



1245
1246
1247
# File 'lib/syntax_tree.rb', line 1245

def child_nodes
  [value]
end

#format(q) ⇒ Object



1249
1250
1251
1252
# File 'lib/syntax_tree.rb', line 1249

def format(q)
  q.text("*")
  q.format(value) if value
end

#pretty_print(q) ⇒ Object



1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
# File 'lib/syntax_tree.rb', line 1254

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

    q.breakable
    q.pp(value)

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

#to_json(*opts) ⇒ Object



1265
1266
1267
1268
1269
# File 'lib/syntax_tree.rb', line 1265

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