aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/gems/rdoc-2.4.3/lib/rdoc/attr.rb
blob: 235a5ab23dff6d40c58d61f611553649189c9aea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require 'rdoc/code_object'

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

class RDoc::Attr < RDoc::CodeObject

  ##
  # Name of the attribute

  attr_accessor :name

  ##
  # Is the attribute readable, writable or both?

  attr_accessor :rw

  ##
  # Source file token stream

  attr_accessor :text

  ##
  # public, protected, private

  attr_accessor :visibility

  def initialize(text, name, rw, comment)
    super()
    @text = text
    @name = name
    @rw = rw
    @visibility = :public
    self.comment = comment
  end

  ##
  # Attributes are ordered by name

  def <=>(other)
    self.name <=> other.name
  end

  ##
  # An HTML id-friendly representation of #name

  def html_name
    @name.gsub(/[^a-z]+/, '-')
  end

  def inspect # :nodoc:
    attr = case rw
           when 'RW' then :attr_accessor
           when 'R'  then :attr_reader
           when 'W'  then :attr_writer
           else
               " (#{rw})"
           end

      "#<%s:0x%x %s.%s :%s>" % [
        self.class, object_id,
        parent_name, attr, @name,
      ]
  end

  ##
  # URL path for this attribute

  def path
    "#{@parent.path}##{@name}"
  end

  def to_s # :nodoc:
    "attr: #{self.name} #{self.rw}\n#{self.comment}"
  end

end