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.



13547
13548
13549
13550
13551
# File 'lib/syntax_tree.rb', line 13547

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



13539
13540
13541
# File 'lib/syntax_tree.rb', line 13539

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



13545
13546
13547
# File 'lib/syntax_tree.rb', line 13545

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



13542
13543
13544
# File 'lib/syntax_tree.rb', line 13542

def location
  @location
end

Instance Method Details

#child_nodesObject



13553
13554
13555
# File 'lib/syntax_tree.rb', line 13553

def child_nodes
  [arguments]
end

#format(q) ⇒ Object



13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
# File 'lib/syntax_tree.rb', line 13557

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



13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
# File 'lib/syntax_tree.rb', line 13575

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



13586
13587
13588
13589
13590
# File 'lib/syntax_tree.rb', line 13586

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