Class: SyntaxTree::ArgBlock

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

ArgBlock represents using a block operator on an expression.

method(&expression)

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

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

Returns a new instance of ArgBlock.



614
615
616
617
618
# File 'lib/syntax_tree/node.rb', line 614

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



612
613
614
# File 'lib/syntax_tree/node.rb', line 612

def comments
  @comments
end

#valueObject (readonly)

nil | untyped

the expression being turned into a block



609
610
611
# File 'lib/syntax_tree/node.rb', line 609

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



620
621
622
# File 'lib/syntax_tree/node.rb', line 620

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

#child_nodesObject Also known as: deconstruct



624
625
626
# File 'lib/syntax_tree/node.rb', line 624

def child_nodes
  [value]
end

#deconstruct_keys(keys) ⇒ Object



630
631
632
# File 'lib/syntax_tree/node.rb', line 630

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

#format(q) ⇒ Object



634
635
636
637
# File 'lib/syntax_tree/node.rb', line 634

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