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.



1252
1253
1254
1255
1256
# File 'lib/syntax_tree.rb', line 1252

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



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

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



1247
1248
1249
# File 'lib/syntax_tree.rb', line 1247

def location
  @location
end

#valueObject (readonly)

nil | untyped

the expression being splatted



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

def value
  @value
end

Instance Method Details

#child_nodesObject



1258
1259
1260
# File 'lib/syntax_tree.rb', line 1258

def child_nodes
  [value]
end

#format(q) ⇒ Object



1262
1263
1264
1265
# File 'lib/syntax_tree.rb', line 1262

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

#pretty_print(q) ⇒ Object



1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
# File 'lib/syntax_tree.rb', line 1267

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



1278
1279
1280
1281
1282
# File 'lib/syntax_tree.rb', line 1278

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