class RDoc::Constant

一个常量

属性

is_alias_for[W]

设置此常量作为别名的模块或类。

name[RW]

常量的名称

value[RW]

常量的值

visibility[RW]

常量的可见性

公共类方法

new(name, value, comment) 点击切换源代码

使用 namevaluecomment 创建一个新的常量

调用父类方法 RDoc::CodeObject::new
# File rdoc/code_object/constant.rb, line 32
def initialize(name, value, comment)
  super()

  @name  = name
  @value = value

  @is_alias_for = nil
  @visibility   = :public

  self.comment = comment
end

公共实例方法

<=>(other) 点击切换源代码

常量按名称排序

# File rdoc/code_object/constant.rb, line 47
def <=> other
  return unless self.class === other

  [parent_name, name] <=> [other.parent_name, other.name]
end
==(other) 点击切换源代码

当它们的 parentname 相同时,常量相等

# File rdoc/code_object/constant.rb, line 56
def == other
  self.class == other.class and
    @parent == other.parent and
    @name == other.name
end
documented?() 点击切换源代码

如果一个常量有注释,或者是一个已文档化的类或模块的别名,则该常量被认为是已文档化的。

调用父类方法 RDoc::CodeObject#documented?
# File rdoc/code_object/constant.rb, line 66
def documented?
  return true if super
  return false unless @is_alias_for
  case @is_alias_for
  when String then
    found = @store.find_class_or_module @is_alias_for
    return false unless found
    @is_alias_for = found
  end
  @is_alias_for.documented?
end
full_name() 点击切换源代码

包含命名空间的完整常量名称

# File rdoc/code_object/constant.rb, line 81
def full_name
  @full_name ||= "#{parent_name}::#{@name}"
end
is_alias_for() 点击切换源代码

此常量作为别名的模块或类

# File rdoc/code_object/constant.rb, line 88
def is_alias_for
  case @is_alias_for
  when String then
    found = @store.find_class_or_module @is_alias_for
    @is_alias_for = found if found
    @is_alias_for
  else
    @is_alias_for
  end
end
marshal_dump() 点击切换源代码

转储此 Constant 以供 ri 使用。另请参见 marshal_load

# File rdoc/code_object/constant.rb, line 109
def marshal_dump
  alias_name = case found = is_alias_for
               when RDoc::CodeObject then found.full_name
               else                       found
               end

  [ MARSHAL_VERSION,
    @name,
    full_name,
    @visibility,
    alias_name,
    parse(@comment),
    @file.relative_name,
    parent.name,
    parent.class,
    section.title,
  ]
end
marshal_load(array) 点击切换源代码

array 加载此 Constant。对于已加载的 Constant,以下方法将返回缓存的值

# File rdoc/code_object/constant.rb, line 135
def marshal_load array
  initialize array[1], nil, array[5]

  @full_name     = array[2]
  @visibility    = array[3] || :public
  @is_alias_for  = array[4]
  #                      5 handled above
  #                      6 handled below
  @parent_name   = array[7]
  @parent_class  = array[8]
  @section_title = array[9]

  @file = RDoc::TopLevel.new array[6]
end
path() 点击切换源代码

此常量的路径,用于 HTML 生成器输出。

# File rdoc/code_object/constant.rb, line 153
def path
  "#{@parent.path}##{@name}"
end
store=(store) 点击切换源代码

设置此类或模块及其包含的代码对象的存储。

调用父类方法 RDoc::CodeObject#store=
# File rdoc/code_object/constant.rb, line 171
def store= store
  super

  @file = @store.add_file @file.full_name if @file
end