summaryrefslogtreecommitdiff
path: root/lib/rdoc/constant.rb
blob: 908990855d1cb33b5abffe566daf6fc95dbf9baf (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
require 'rdoc/code_object'

##
# A constant

class RDoc::Constant < RDoc::CodeObject

  ##
  # The constant's name

  attr_accessor :name

  ##
  # The constant's value

  attr_accessor :value

  ##
  # Creates a new constant with +name+, +value+ and +comment+

  def initialize(name, value, comment)
    super()
    @name = name
    @value = value
    self.comment = comment
  end

  ##
  # Constants are ordered by name

  def <=> other
    return unless self.class === other

    [parent_name, name] <=> [other.parent_name, other.name]
  end

  def == other
    self.class == other.class and
      @parent == other.parent and
      @name == other.name
  end

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

  ##
  # Path to this constant

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

end