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:) ⇒ AssocSplat

Returns a new instance of AssocSplat.



1567
1568
1569
1570
1571
# File 'lib/syntax_tree/node.rb', line 1567

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



1565
1566
1567
# File 'lib/syntax_tree/node.rb', line 1565

def comments
  @comments
end

#valueObject (readonly)

nil | untyped

the expression that is being splatted



1562
1563
1564
# File 'lib/syntax_tree/node.rb', line 1562

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



1603
1604
1605
# File 'lib/syntax_tree/node.rb', line 1603

def ===(other)
  other.is_a?(AssocSplat) && value === other.value
end

#accept(visitor) ⇒ Object



1573
1574
1575
# File 'lib/syntax_tree/node.rb', line 1573

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

#child_nodesObject Also known as: deconstruct



1577
1578
1579
# File 'lib/syntax_tree/node.rb', line 1577

def child_nodes
  [value]
end

#copy(value: nil, location: nil) ⇒ Object



1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
# File 'lib/syntax_tree/node.rb', line 1581

def copy(value: nil, location: nil)
  node =
    AssocSplat.new(
      value: value || self.value,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



1594
1595
1596
# File 'lib/syntax_tree/node.rb', line 1594

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

#format(q) ⇒ Object



1598
1599
1600
1601
# File 'lib/syntax_tree/node.rb', line 1598

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