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.
1578
1579
1580
1581
1582
|
# File 'lib/syntax_tree/node.rb', line 1578
def initialize(value:, location:)
@value = value
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1576
1577
1578
|
# File 'lib/syntax_tree/node.rb', line 1576
def
@comments
end
|
#value ⇒ Object
- nil | Node
-
the expression that is being splatted
1573
1574
1575
|
# File 'lib/syntax_tree/node.rb', line 1573
def value
@value
end
|
Instance Method Details
#===(other) ⇒ Object
1614
1615
1616
|
# File 'lib/syntax_tree/node.rb', line 1614
def ===(other)
other.is_a?(AssocSplat) && value === other.value
end
|
#accept(visitor) ⇒ Object
1584
1585
1586
|
# File 'lib/syntax_tree/node.rb', line 1584
def accept(visitor)
visitor.visit_assoc_splat(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
1588
1589
1590
|
# File 'lib/syntax_tree/node.rb', line 1588
def child_nodes
[value]
end
|
#copy(value: nil, location: nil) ⇒ Object
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
|
# File 'lib/syntax_tree/node.rb', line 1592
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
1605
1606
1607
|
# File 'lib/syntax_tree/node.rb', line 1605
def deconstruct_keys(_keys)
{ value: value, location: location, comments: }
end
|
1609
1610
1611
1612
|
# File 'lib/syntax_tree/node.rb', line 1609
def format(q)
q.text("**")
q.format(value) if value
end
|