class YARD::CodeObjects::ClassObject
with extra inheritance semantics through the superclass.
A ClassObject represents a Ruby class in source code. It is a {ModuleObject}
def constants(opts = {})
-
(Array
- the list of constant that matched)
Options Hash:
(**opts)
-
:included
(Boolean
) -- whether mixed in constant should be -
:inherited
(Boolean
) -- whether inherited constant should be
Parameters:
-
opts
(Hash
) -- the options hash to match
def constants(opts = {}) opts = SymbolHash[:inherited => true].update(opts) super(opts) + (opts[:inherited] ? inherited_constants : []) end
def inheritance_tree(include_mods = false)
-
(Array
- the list of code objects that make up)
Parameters:
-
include_mods
(Boolean
) -- whether or not to include mixins in the
def inheritance_tree(include_mods = false) list = (include_mods ? mixins(:instance, :class) : []) if superclass.is_a?(Proxy) || superclass.respond_to?(:inheritance_tree) list += [superclass] unless superclass == P(:Object) || superclass == P(:BasicObject) end [self] + list.map do |m| next m if m == self next m unless m.respond_to?(:inheritance_tree) m.inheritance_tree(include_mods) end.flatten.uniq end
def inherited_constants
-
(Array
- the list of inherited constant objects)
def inherited_constants inheritance_tree[1..-1].inject([]) do |list, superclass| if superclass.is_a?(Proxy) list else list += superclass.constants.reject do |o| child(:name => o.name) || list.find {|o2| o2.name == o.name } end end end end
def inherited_meths(opts = {})
-
(Array
- the list of inherited method objects)
def inherited_meths(opts = {}) inheritance_tree[1..-1].inject([]) do |list, superclass| if superclass.is_a?(Proxy) list else list += superclass.meths(opts).reject do |o| next(false) if opts[:all] child(:name => o.name, :scope => o.scope) || list.find {|o2| o2.name == o.name && o2.scope == o.scope } end end end end
def initialize(namespace, name, *args, &block)
- See: Base.new -
def initialize(namespace, name, *args, &block) super if is_exception? self.superclass ||= "::Exception" unless P(namespace, name) == P(:Exception) else case P(namespace, name).path when "BasicObject" nil when "Object" self.superclass ||= "::BasicObject" else self.superclass ||= "::Object" end end end
def is_exception?
-
(Boolean)
- whether the object represents a Ruby exception
def is_exception? inheritance_tree.reverse.any? {|o| BUILTIN_EXCEPTIONS_HASH.key? o.path } end
def meths(opts = {})
-
(Array
- the list of methods that matched)
Options Hash:
(**opts)
-
:included
(Boolean
) -- whether mixed in methods should be -
:inherited
(Boolean
) -- whether inherited methods should be
Parameters:
-
opts
(Hash
) -- the options hash to match
def meths(opts = {}) opts = SymbolHash[:inherited => true].update(opts) list = super(opts) list += inherited_meths(opts).reject do |o| next(false) if opts[:all] list.find {|o2| o2.name == o.name && o2.scope == o.scope } end if opts[:inherited] list end
def superclass=(object)
-
(void)
-
Parameters:
-
object
(Base, Proxy, String, Symbol, nil
) -- the superclass value
def superclass=(object) case object when Base, Proxy, NilClass @superclass = object when String, Symbol @superclass = Proxy.new(namespace, object) else raise ArgumentError, "superclass must be CodeObject, Proxy, String or Symbol" end if name == @superclass.name && namespace != YARD::Registry.root && !object.is_a?(Base) @superclass = Proxy.new(namespace.namespace, object) end if @superclass == self msg = "superclass #{@superclass.inspect} cannot be the same as the declared class #{inspect}" @superclass = P("::Object") raise ArgumentError, msg end end