Method: YARD::CodeObjects::Base#initialize

Defined in:
lib/yard/code_objects/base.rb

#initialize(namespace, name) {|self| ... } ⇒ Base

Creates a new code object

Examples:

Create a method in the root namespace

CodeObjects::Base.new(:root, '#method') # => #<yardoc method #method>

Create class Z inside namespace X::Y

CodeObjects::Base.new(P("X::Y"), :Z) # or
CodeObjects::Base.new(Registry.root, "X::Y")

Parameters:

  • namespace (NamespaceObject)

    the namespace the object belongs in, Registry.root or :root should be provided if it is associated with the top level namespace.

  • name (Symbol, String)

    the name (or complex path) of the object.

Yields:

  • (self)

    a block to perform any extra initialization on the object

Yield Parameters:

  • self (Base)

    the newly initialized code object

[View source]

238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/yard/code_objects/base.rb', line 238

def initialize(namespace, name, *)
  if namespace && namespace != :root &&
     !namespace.is_a?(NamespaceObject) && !namespace.is_a?(Proxy)
    raise ArgumentError, "Invalid namespace object: #{namespace}"
  end

  @files = []
  @current_file_has_comments = false
  @name = name.to_sym
  @source_type = :ruby
  @visibility = :public
  @tags = []
  @docstrings = {}
  @docstring = Docstring.new!('', [], self)
  @namespace = nil
  self.namespace = namespace
  yield(self) if block_given?
end