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.



674
675
676
677
678
# File 'lib/syntax_tree/node.rb', line 674

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



672
673
674
# File 'lib/syntax_tree/node.rb', line 672

def comments
  @comments
end

#valueObject (readonly)

nil | untyped

the expression being turned into a block



669
670
671
# File 'lib/syntax_tree/node.rb', line 669

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



680
681
682
# File 'lib/syntax_tree/node.rb', line 680

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  [value]
end

#deconstruct_keys(_keys) ⇒ Object



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

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

#format(q) ⇒ Object



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

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