Class: SyntaxTree::Yield

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

Overview

Yield represents using the yield keyword with arguments.

yield value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Yield.



13842
13843
13844
13845
13846
# File 'lib/syntax_tree.rb', line 13842

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



13834
13835
13836
# File 'lib/syntax_tree.rb', line 13834

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



13840
13841
13842
# File 'lib/syntax_tree.rb', line 13840

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



13837
13838
13839
# File 'lib/syntax_tree.rb', line 13837

def location
  @location
end

Instance Method Details

#child_nodesObject



13848
13849
13850
# File 'lib/syntax_tree.rb', line 13848

def child_nodes
  [arguments]
end

#format(q) ⇒ Object



13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
# File 'lib/syntax_tree.rb', line 13852

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

#pretty_print(q) ⇒ Object



13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
# File 'lib/syntax_tree.rb', line 13870

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

    q.breakable
    q.pp(arguments)

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

#to_json(*opts) ⇒ Object



13881
13882
13883
13884
13885
# File 'lib/syntax_tree.rb', line 13881

def to_json(*opts)
  { type: :yield, args: arguments, loc: location, cmts: comments }.to_json(
    *opts
  )
end