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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ArgBlock.



782
783
784
785
786
# File 'lib/syntax_tree/node.rb', line 782

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



780
781
782
# File 'lib/syntax_tree/node.rb', line 780

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



777
778
779
# File 'lib/syntax_tree/node.rb', line 777

def location
  @location
end

#valueObject (readonly)

nil | untyped

the expression being turned into a block



774
775
776
# File 'lib/syntax_tree/node.rb', line 774

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



788
789
790
# File 'lib/syntax_tree/node.rb', line 788

def child_nodes
  [value]
end

#deconstruct_keys(keys) ⇒ Object



794
795
796
# File 'lib/syntax_tree/node.rb', line 794

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

#format(q) ⇒ Object



798
799
800
801
# File 'lib/syntax_tree/node.rb', line 798

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

#pretty_print(q) ⇒ Object



803
804
805
806
807
808
809
810
811
812
813
814
# File 'lib/syntax_tree/node.rb', line 803

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("arg_block")

    if value
      q.breakable
      q.pp(value)
    end

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



816
817
818
819
820
# File 'lib/syntax_tree/node.rb', line 816

def to_json(*opts)
  { type: :arg_block, value: value, loc: location, cmts: comments }.to_json(
    *opts
  )
end