Class: SyntaxTree::AssocSplat
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::AssocSplat
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, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(value:, location:) ⇒ AssocSplat
Returns a new instance of AssocSplat.
1582
1583
1584
1585
1586
|
# File 'lib/syntax_tree/node.rb', line 1582
def initialize(value:, location:)
@value = value
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1580
1581
1582
|
# File 'lib/syntax_tree/node.rb', line 1580
def
@comments
end
|
#value ⇒ Object
- nil | Node
-
the expression that is being splatted
1577
1578
1579
|
# File 'lib/syntax_tree/node.rb', line 1577
def value
@value
end
|
Instance Method Details
#===(other) ⇒ Object
1618
1619
1620
|
# File 'lib/syntax_tree/node.rb', line 1618
def ===(other)
other.is_a?(AssocSplat) && value === other.value
end
|
#accept(visitor) ⇒ Object
1588
1589
1590
|
# File 'lib/syntax_tree/node.rb', line 1588
def accept(visitor)
visitor.visit_assoc_splat(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
1592
1593
1594
|
# File 'lib/syntax_tree/node.rb', line 1592
def child_nodes
[value]
end
|
#copy(value: nil, location: nil) ⇒ Object
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
|
# File 'lib/syntax_tree/node.rb', line 1596
def copy(value: nil, location: nil)
node =
AssocSplat.new(
value: value || self.value,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
1609
1610
1611
|
# File 'lib/syntax_tree/node.rb', line 1609
def deconstruct_keys(_keys)
{ value: value, location: location, comments: }
end
|
1613
1614
1615
1616
|
# File 'lib/syntax_tree/node.rb', line 1613
def format(q)
q.text("**")
q.format(value) if value
end
|