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

Constructor Details

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

Returns a new instance of AssocSplat.



1460
1461
1462
1463
1464
# File 'lib/syntax_tree/node.rb', line 1460

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



1458
1459
1460
# File 'lib/syntax_tree/node.rb', line 1458

def comments
  @comments
end

#valueObject (readonly)

untyped

the expression that is being splatted



1455
1456
1457
# File 'lib/syntax_tree/node.rb', line 1455

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



1466
1467
1468
# File 'lib/syntax_tree/node.rb', line 1466

def child_nodes
  [value]
end

#deconstruct_keys(keys) ⇒ Object



1472
1473
1474
# File 'lib/syntax_tree/node.rb', line 1472

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

#format(q) ⇒ Object



1476
1477
1478
1479
# File 'lib/syntax_tree/node.rb', line 1476

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

#pretty_print(q) ⇒ Object



1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
# File 'lib/syntax_tree/node.rb', line 1481

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



1492
1493
1494
1495
1496
1497
1498
1499
# File 'lib/syntax_tree/node.rb', line 1492

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