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

#pretty_print, #to_json

Constructor Details

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

Returns a new instance of AssocSplat.



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

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



1228
1229
1230
# File 'lib/syntax_tree/node.rb', line 1228

def comments
  @comments
end

#valueObject (readonly)

untyped

the expression that is being splatted



1225
1226
1227
# File 'lib/syntax_tree/node.rb', line 1225

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  [value]
end

#deconstruct_keys(keys) ⇒ Object



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

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

#format(q) ⇒ Object



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

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