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:) ⇒ ArgBlock

Returns a new instance of ArgBlock.



864
865
866
867
868
# File 'lib/syntax_tree/node.rb', line 864

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



862
863
864
# File 'lib/syntax_tree/node.rb', line 862

def comments
  @comments
end

#valueObject (readonly)

nil | untyped

the expression being turned into a block



859
860
861
# File 'lib/syntax_tree/node.rb', line 859

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



870
871
872
# File 'lib/syntax_tree/node.rb', line 870

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

#child_nodesObject Also known as: deconstruct



874
875
876
# File 'lib/syntax_tree/node.rb', line 874

def child_nodes
  [value]
end

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



878
879
880
881
882
883
884
885
886
887
# File 'lib/syntax_tree/node.rb', line 878

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



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

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

#format(q) ⇒ Object



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

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