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.



13037
13038
13039
13040
13041
# File 'lib/syntax_tree.rb', line 13037

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



13029
13030
13031
# File 'lib/syntax_tree.rb', line 13029

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



13035
13036
13037
# File 'lib/syntax_tree.rb', line 13035

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



13032
13033
13034
# File 'lib/syntax_tree.rb', line 13032

def location
  @location
end

Instance Method Details

#child_nodesObject



13043
13044
13045
# File 'lib/syntax_tree.rb', line 13043

def child_nodes
  [arguments]
end

#format(q) ⇒ Object



13047
13048
13049
13050
13051
13052
13053
# File 'lib/syntax_tree.rb', line 13047

def format(q)
  q.group do
    q.text("yield")
    q.text(" ") if arguments.is_a?(Args)
    q.format(arguments)
  end
end

#pretty_print(q) ⇒ Object



13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
# File 'lib/syntax_tree.rb', line 13055

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



13066
13067
13068
13069
13070
# File 'lib/syntax_tree.rb', line 13066

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