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, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(value:, location:) ⇒ ArgBlock

Returns a new instance of ArgBlock.



893
894
895
896
897
# File 'lib/syntax_tree/node.rb', line 893

def initialize(value:, location:)
  @value = value
  @location = location
  @comments = []
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



891
892
893
# File 'lib/syntax_tree/node.rb', line 891

def comments
  @comments
end

#valueObject (readonly)

nil | Node

the expression being turned into a block



888
889
890
# File 'lib/syntax_tree/node.rb', line 888

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



929
930
931
# File 'lib/syntax_tree/node.rb', line 929

def ===(other)
  other.is_a?(ArgBlock) && value === other.value
end

#accept(visitor) ⇒ Object



899
900
901
# File 'lib/syntax_tree/node.rb', line 899

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

#child_nodesObject Also known as: deconstruct



903
904
905
# File 'lib/syntax_tree/node.rb', line 903

def child_nodes
  [value]
end

#copy(value: nil, location: nil) ⇒ Object



907
908
909
910
911
912
913
914
915
916
# File 'lib/syntax_tree/node.rb', line 907

def copy(value: nil, location: nil)
  node =
    ArgBlock.new(
      value: value || self.value,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



920
921
922
# File 'lib/syntax_tree/node.rb', line 920

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

#format(q) ⇒ Object



924
925
926
927
# File 'lib/syntax_tree/node.rb', line 924

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