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.



13638
13639
13640
13641
13642
# File 'lib/syntax_tree.rb', line 13638

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



13630
13631
13632
# File 'lib/syntax_tree.rb', line 13630

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



13636
13637
13638
# File 'lib/syntax_tree.rb', line 13636

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



13633
13634
13635
# File 'lib/syntax_tree.rb', line 13633

def location
  @location
end

Instance Method Details

#child_nodesObject



13644
13645
13646
# File 'lib/syntax_tree.rb', line 13644

def child_nodes
  [arguments]
end

#format(q) ⇒ Object



13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
# File 'lib/syntax_tree.rb', line 13648

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



13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
# File 'lib/syntax_tree.rb', line 13666

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



13677
13678
13679
13680
13681
# File 'lib/syntax_tree.rb', line 13677

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