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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of AssocSplat.



1508
1509
1510
1511
1512
# File 'lib/syntax_tree/node.rb', line 1508

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



1506
1507
1508
# File 'lib/syntax_tree/node.rb', line 1506

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



1503
1504
1505
# File 'lib/syntax_tree/node.rb', line 1503

def location
  @location
end

#valueObject (readonly)

untyped

the expression that is being splatted



1500
1501
1502
# File 'lib/syntax_tree/node.rb', line 1500

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



1514
1515
1516
# File 'lib/syntax_tree/node.rb', line 1514

def child_nodes
  [value]
end

#deconstruct_keys(keys) ⇒ Object



1520
1521
1522
# File 'lib/syntax_tree/node.rb', line 1520

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

#format(q) ⇒ Object



1524
1525
1526
1527
# File 'lib/syntax_tree/node.rb', line 1524

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

#pretty_print(q) ⇒ Object



1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
# File 'lib/syntax_tree/node.rb', line 1529

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("assoc_splat")

    q.breakable
    q.pp(value)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



1540
1541
1542
1543
1544
1545
1546
1547
# File 'lib/syntax_tree/node.rb', line 1540

def to_json(*opts)
  {
    type: :assoc_splat,
    value: value,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end