Class: RDoc::Attr

Inherits:
MethodAttr show all
Includes:
Generator::Markup
Defined in:
lib/rdoc/attr.rb,
lib/rdoc/generator/markup.rb

Overview

An attribute created by #attr, #attr_reader, #attr_writer or #attr_accessor

Constant Summary

MARSHAL_VERSION =

:nodoc:

1

Constants included from Text

Text::TO_HTML_CHARACTERS

Instance Attribute Summary (collapse)

Attributes inherited from MethodAttr

#aliases, #arglists, #block_params, #call_seq, #is_alias_for, #name, #param_seq, #params, #singleton, #text, #visibility

Attributes inherited from CodeObject

#comment, #document_children, #document_self, #done_documenting, #file, #force_documentation, #line, #metadata, #offset, #parent, #received_nodoc, #section, #viewer

Instance Method Summary (collapse)

Methods included from Generator::Markup

#aref_to, #as_href, #cvs_url, #description, #formatter

Methods inherited from MethodAttr

#<=>, #aref, #documented?, #find_method_or_attribute, #find_see, #full_name, #html_name, #inspect, #name_prefix, #parent_name, #path, #pretty_name, #pretty_print, #see, #type

Methods inherited from CodeObject

#documented?, #full_name=, #parent_file_name, #parent_name, #record_location, #start_doc, #stop_doc

Methods included from Text

encode_fallback, #expand_tabs, #flush_left, #markup, #normalize_comment, #parse, #strip_hashes, #strip_newlines, #strip_stars, #to_html, #wrap

Constructor Details

- (Attr) initialize(text, name, rw, comment, singleton = false)

Creates a new Attr with body text, name, read/write status rw and comment. singleton marks this as a class attribute.



20
21
22
23
24
25
26
# File 'lib/rdoc/attr.rb', line 20

def initialize(text, name, rw, comment, singleton = false)
  super text, name

  @rw = rw
  @singleton = singleton
  self.comment = comment
end

Instance Attribute Details

- (Object) rw

Is the attribute readable ('R'), writable ('W') or both ('RW')?



14
15
16
# File 'lib/rdoc/attr.rb', line 14

def rw
  @rw
end

Instance Method Details

- (Object) ==(other)

Attributes are equal when their names, singleton and rw are identical



31
32
33
34
35
36
# File 'lib/rdoc/attr.rb', line 31

def == other
  self.class == other.class and
    self.name == other.name and
    self.rw == other.rw and
    self.singleton == other.singleton
end

- (Object) add_alias(an_alias, context)

Add an_alias as an attribute in context.



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rdoc/attr.rb', line 41

def add_alias(an_alias, context)
  new_attr = self.class.new(self.text, an_alias.new_name, self.rw,
                            self.comment, self.singleton)

  new_attr.record_location an_alias.file
  new_attr.visibility = self.visibility
  new_attr.is_alias_for = self
  @aliases << new_attr
  context.add_attribute new_attr
  new_attr
end

- (Object) aref_prefix

The #aref prefix for attributes



56
57
58
# File 'lib/rdoc/attr.rb', line 56

def aref_prefix
  'attribute'
end

- (Object) definition

Returns attr_reader, attr_writer or attr_accessor as appropriate.



63
64
65
66
67
68
69
# File 'lib/rdoc/attr.rb', line 63

def definition
  case @rw
  when 'RW' then 'attr_accessor'
  when 'R'  then 'attr_reader'
  when 'W'  then 'attr_writer'
  end
end

- (Object) marshal_dump

Dumps this Attr for use by ri. See also #marshal_load



74
75
76
77
78
79
80
81
82
83
# File 'lib/rdoc/attr.rb', line 74

def marshal_dump
  [ MARSHAL_VERSION,
    @name,
    full_name,
    @rw,
    @visibility,
    parse(@comment),
    singleton,
  ]
end

- (Object) marshal_load(array)

Loads this Attr from array. For a loaded Attr the following methods will return cached values:

  • #full_name

  • #parent_name



92
93
94
95
96
97
98
99
100
101
# File 'lib/rdoc/attr.rb', line 92

def marshal_load array
  @name       = array[1]
  @full_name  = array[2]
  @rw         = array[3]
  @visibility = array[4]
  @comment    = array[5]
  @singleton  = array[6] || false # MARSHAL_VERSION == 0

  @parent_name = @full_name
end

- (Object) to_s

:nodoc:



103
104
105
# File 'lib/rdoc/attr.rb', line 103

def to_s # :nodoc:
  "#{definition} #{name} in: #{parent}"
end