Class: YARD::Parser::Ruby::ParameterNode

Inherits:
AstNode show all
Defined in:
lib/yard/parser/ruby/ast_node.rb

Managing node state collapse

Constructor Details

This class inherits a constructor from YARD::Parser::Ruby::AstNode

Instance Method Details

#block_paramObject


425
426
427
# File 'lib/yard/parser/ruby/ast_node.rb', line 425

def block_param
  self[-1] ? self[-1][0] : nil
end

#double_splat_paramObject


413
414
415
416
417
418
419
420
421
422
423
# File 'lib/yard/parser/ruby/ast_node.rb', line 413

def double_splat_param
  return nil unless YARD.ruby2?
  if (node = self[-2]).is_a?(AstNode)
    if node.type == :ident
      node
    elsif node.type == :kwrest_param
      # See https://bugs.ruby-lang.org/issues/12387
      node.last
    end
  end
end

#named_paramsObject


395
396
397
398
399
400
401
402
403
# File 'lib/yard/parser/ruby/ast_node.rb', line 395

def named_params
  return @named_params if defined?(@named_params)

  if YARD.ruby2? && self[-3] && self[-3][0] && self[-3][0].type == :named_arg
    @named_params = self[-3]
  else
    @named_params = nil
  end
end

#splat_paramObject


405
406
407
# File 'lib/yard/parser/ruby/ast_node.rb', line 405

def splat_param
  self[2] ? self[2][0] : nil
end

#unnamed_end_paramsObject


409
410
411
# File 'lib/yard/parser/ruby/ast_node.rb', line 409

def unnamed_end_params
  self[3]
end

#unnamed_optional_paramsObject


384
385
386
387
388
389
390
391
392
393
# File 'lib/yard/parser/ruby/ast_node.rb', line 384

def unnamed_optional_params
  return @unnamed_optional_params if defined?(@unnamed_optional_params)

  params = self[1] || []
  if self[-3] && self[-3][0] && self[-3][0].type == :unnamed_optional_arg
    params += self[-3]
  end

  @unnamed_optional_params = params.empty? ? nil : params
end

#unnamed_required_paramsObject


380
381
382
# File 'lib/yard/parser/ruby/ast_node.rb', line 380

def unnamed_required_params
  self[0]
end