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

#construct_keys, #pretty_print, #to_json

Constructor Details

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

Returns a new instance of ArgBlock.



689
690
691
692
693
# File 'lib/syntax_tree/node.rb', line 689

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



687
688
689
# File 'lib/syntax_tree/node.rb', line 687

def comments
  @comments
end

#valueObject (readonly)

nil | untyped

the expression being turned into a block



684
685
686
# File 'lib/syntax_tree/node.rb', line 684

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



695
696
697
# File 'lib/syntax_tree/node.rb', line 695

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

#child_nodesObject Also known as: deconstruct



699
700
701
# File 'lib/syntax_tree/node.rb', line 699

def child_nodes
  [value]
end

#deconstruct_keys(_keys) ⇒ Object



705
706
707
# File 'lib/syntax_tree/node.rb', line 705

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

#format(q) ⇒ Object



709
710
711
712
# File 'lib/syntax_tree/node.rb', line 709

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