# Class: YARD::Tags::AttributeDirective

Inherits:
  MethodDirective
  - Object
  - Directive
  - MethodDirective
  - YARD::Tags::AttributeDirective
  show all

Defined in:
  lib/yard/tags/directives.rb

## Overview

Note:

This directive should only be used if there is no explicit `attr_*` declaration for the attribute in any source files (i.e., the attribute is declared dynamically via meta-programming). In all other cases, add documentation to the attribute declaration itself.

Note:

For backwards compatibility support, you do not need to indent the attribute’s docstring text. If an `@!attribute` directive is seen with no indented block, the entire docstring is used as the new attribute’s docstring text.

Defines an attribute with a given name, using indented block data as the attribute’s docstring. If the type specifier is supplied with “r”, “w”, or “rw”, the attribute is made readonly, writeonly or readwrite respectively. A readwrite attribute is the default, if no type is specified. 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 a regular method, see @!method

#### Examples:

#####

Defining a simple readonly attribute

    # @!attribute [r] count
    #   @return [Fixnum] the size of the list

#####

Defining a simple readwrite attribute

    # @!attribute name
    #   @return [String] the name of the user

See Also:

- @!method

Since:

- 0.7.0

## Parser callbacks collapse

- #after_parse ⇒ Object
- #method_name ⇒ Object protected
- #method_signature ⇒ Object protected

## Constructor Details

This class inherits a constructor from YARD::Tags::Directive

## Instance Method Details

### #after_parse ⇒ `Object`

Since:

- 0.7.0

    461
    462
    463
    464
    465

    # File 'lib/yard/tags/directives.rb', line 461

    def after_parse
      return unless handler
      use_indented_text
      create_attribute_data(create_object)
    end

### #method_name ⇒ `Object` (protected)

Since:

- 0.7.0

    469
    470
    471
    472
    473

    # File 'lib/yard/tags/directives.rb', line 469

    def method_name
      name = sanitized_tag_signature || handler.call_params.first
      name += '=' unless readable?
      name
    end

### #method_signature ⇒ `Object` (protected)

Since:

- 0.7.0

    475
    476
    477
    478
    479
    480
    481

    # File 'lib/yard/tags/directives.rb', line 475

    def method_signature
      if readable?
        "def #{method_name}"
      else
        "def #{method_name}(value)"
      end
    end