Class/Module Index [+]

Quicksearch

YARD::Tags::MethodDirective

Defines a method object with a given method signature, using indented block data as the method's docstring. The signature is similar to the {tag:overload} tag. The comment containing this directive does not need to be attached to any source, but if it is, that source code will be used as the method's source.

To define an attribute method, see {tag:!attribute}

@note For backwards compatibility support, you do not need to indent

the method's docstring text. If a +@!method+ directive is seen with
no indented block, the entire docstring is used as the new method's
docstring text.

@example Defining a simple method

# @!method quit(username, message = "Quit")
#   Sends a quit message to the server for a +username+.
#   @param [String] username the username to quit
#   @param [String] message the quit message
quit_message_method

@example Attaching multiple methods to the same source

# @!method method1
# @!method method2
create_methods :method1, :method2

@see tag:!attribute @since 0.7.0

Constants

SCOPE_MATCH

Public Instance Methods

after_parse() click to toggle source
# File lib/yard/tags/directives.rb, line 355
def after_parse
  return unless handler
  use_indented_text
  create_object
end
call() click to toggle source
# File lib/yard/tags/directives.rb, line 353
def call; end

Protected Instance Methods

create_object() click to toggle source
# File lib/yard/tags/directives.rb, line 393
def create_object
  name = method_name
  scope = parser.state.scope || handler.scope
  visibility = parser.state.visibility || handler.visibility
  ns = CodeObjects::NamespaceObject === object ? object : handler.namespace
  obj = CodeObjects::MethodObject.new(ns, name, scope)
  handler.register_file_info(obj)
  handler.register_source(obj)
  handler.register_visibility(obj, visibility)
  handler.register_group(obj)
  obj.signature = method_signature
  obj.parameters = OverloadTag.new(:overload, method_signature).parameters
  obj.docstring = Docstring.new!(parser.text, parser.tags, obj,
    parser.raw_text)
  handler.register_module_function(obj)
  obj
end
method_name() click to toggle source
# File lib/yard/tags/directives.rb, line 363
def method_name
  sig = sanitized_tag_signature
  if sig && sig =~ /^#{CodeObjects::METHODNAMEMATCH}(\s|\(|$)/
    sig[/\A\s*([^\(; \t]+)/, 1]
  else
    handler.call_params.first
  end
end
method_signature() click to toggle source
# File lib/yard/tags/directives.rb, line 372
def method_signature
  "def #{sanitized_tag_signature || method_name}"
end
sanitized_tag_signature() click to toggle source
# File lib/yard/tags/directives.rb, line 376
def sanitized_tag_signature
  if tag.name && tag.name =~ SCOPE_MATCH
    parser.state.scope = :class
    $'
  else
    tag.name
  end
end
use_indented_text() click to toggle source
# File lib/yard/tags/directives.rb, line 385
def use_indented_text
  return if tag.text.empty?
  handler = parser.handler
  object = parser.object
  self.parser = parser.class.new(parser.library)
  parser.parse(tag.text, object, handler)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.