Class: SyntaxTree::AssocSplat

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

Overview

AssocSplat represents double-splatting a value into a hash (either a hash literal or a bare hash in a method call).

{ **pairs }

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #pretty_print, #to_json

Constructor Details

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

Returns a new instance of AssocSplat.



1309
1310
1311
1312
1313
# File 'lib/syntax_tree/node.rb', line 1309

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

Instance Attribute Details

#comments ⇒ Object (readonly)

[Array[ Comment | EmbDoc ]] the comments attached to this node



1307
1308
1309
# File 'lib/syntax_tree/node.rb', line 1307

def comments
  @comments
end

#value ⇒ Object (readonly)

[untyped] the expression that is being splatted



1304
1305
1306
# File 'lib/syntax_tree/node.rb', line 1304

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



1315
1316
1317
# File 'lib/syntax_tree/node.rb', line 1315

def accept(visitor)
  visitor.visit_assoc_splat(self)
end

#child_nodes ⇒ Object Also known as: deconstruct



1319
1320
1321
# File 'lib/syntax_tree/node.rb', line 1319

def child_nodes
  [value]
end

#deconstruct_keys(_keys) ⇒ Object



1325
1326
1327
# File 'lib/syntax_tree/node.rb', line 1325

def deconstruct_keys(_keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



1329
1330
1331
1332
# File 'lib/syntax_tree/node.rb', line 1329

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