Class: SyntaxTree::Yield

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

Yield represents using the yield keyword with arguments.

yield value

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

#initialize(arguments:, location:, comments: []) ⇒ Yield

Returns a new instance of Yield.



9830
9831
9832
9833
9834
# File 'lib/syntax_tree/node.rb', line 9830

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

Instance Attribute Details

#argumentsObject (readonly)

Args | Paren

the arguments passed to the yield



9825
9826
9827
# File 'lib/syntax_tree/node.rb', line 9825

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



9828
9829
9830
# File 'lib/syntax_tree/node.rb', line 9828

def comments
  @comments
end

Instance Method Details

#accept(visitor) ⇒ Object



9836
9837
9838
# File 'lib/syntax_tree/node.rb', line 9836

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

#child_nodesObject Also known as: deconstruct



9840
9841
9842
# File 'lib/syntax_tree/node.rb', line 9840

def child_nodes
  [arguments]
end

#deconstruct_keys(keys) ⇒ Object



9846
9847
9848
# File 'lib/syntax_tree/node.rb', line 9846

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

#format(q) ⇒ Object



9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
# File 'lib/syntax_tree/node.rb', line 9850

def format(q)
  q.group do
    q.text("yield")

    if arguments.is_a?(Paren)
      q.format(arguments)
    else
      q.if_break { q.text("(") }.if_flat { q.text(" ") }
      q.indent do
        q.breakable("")
        q.format(arguments)
      end
      q.breakable("")
      q.if_break { q.text(")") }
    end
  end
end