Class: YARD::CodeObjects::ClassObject
- Inherits:
-
NamespaceObject
- Object
- Base
- NamespaceObject
- YARD::CodeObjects::ClassObject
- Defined in:
- lib/yard/code_objects/class_object.rb
Overview
A ClassObject represents a Ruby class in source code. It is a ModuleObject with extra inheritance semantics through the superclass.
Instance Attribute Summary (collapse)
-
- (Hash) aliases
inherited
from NamespaceObject
readonly
A hash containing two keys, :class and :instance, each containing a hash of objects and their alias names.
-
- (Hash) attributes
inherited
from NamespaceObject
readonly
A hash containing two keys, class and instance, each containing the attribute name with a { :read, :write } hash for the read and write objects respectively.
-
- (Docstring) base_docstring
inherited
from Base
readonly
The non-localized documentation string associated with the object.
-
- (Base?) child(opts = {})
inherited
from NamespaceObject
Looks for a child that matches the attributes specified by
opts
. -
- (Array<Base>) children
inherited
from NamespaceObject
readonly
The list of objects defined in this namespace.
-
- (Hash) class_attributes
inherited
from NamespaceObject
Only the class attributes.
-
- (Array<ModuleObject>) class_mixins
inherited
from NamespaceObject
readonly
Class mixins.
-
- (Array<ConstantObject>) constants(opts = {})
inherited
from NamespaceObject
Returns all constants in the namespace.
-
- (Array<ClassVariableObject>) cvars
inherited
from NamespaceObject
Returns class variables defined in this namespace.
-
- (Boolean) dynamic
inherited
from Base
Marks whether or not the method is conditionally defined at runtime.
-
- (Array<String>) files
inherited
from Base
readonly
The files the object was defined in.
-
- (String) group
inherited
from Base
The group this object is associated with.
-
- (Array<String>) groups
inherited
from NamespaceObject
A list of ordered group names inside the namespace.
-
- (Array<ConstantObject>) included_constants
inherited
from NamespaceObject
Returns constants included from any mixins.
-
- (Object) included_meths(opts = {})
inherited
from NamespaceObject
Returns methods included from any mixins that match the attributes specified by
opts
. -
- (Hash) instance_attributes
inherited
from NamespaceObject
Only the instance attributes.
-
- (Array<ModuleObject>) instance_mixins
inherited
from NamespaceObject
readonly
Instance mixins.
-
- (Array<MethodObject>) meths(opts = {})
inherited
from NamespaceObject
Returns all methods that match the attributes specified by
opts
. -
- (Array<ModuleObject>) mixins(*scopes)
inherited
from NamespaceObject
Returns for specific scopes.
-
- (NamespaceObject) namespace
(also: #parent)
inherited
from Base
The namespace the object is defined in.
-
- (String) signature
inherited
from Base
The one line signature representing an object.
-
- (String?) source
inherited
from Base
The source code associated with the object.
-
- (Symbol) source_type
inherited
from Base
Language of the source code associated with the object.
-
- (ClassObject) superclass
The ClassObject that this class object inherits from in Ruby source.
-
- (Symbol) visibility
inherited
from Base
The visibility of an object (:public, :private, :protected).
Instance Method Summary (collapse)
-
- (Array<ConstantObject>) constants(opts = {})
Returns the list of constants matching the options hash.
-
- (Array<NamespaceObject>) inheritance_tree(include_mods = false)
Returns the inheritance tree of the object including self.
-
- (Array<ConstantObject>) inherited_constants
Returns only the constants that were inherited.
-
- (Array<MethodObject>) inherited_meths(opts = {})
Returns only the methods that were inherited.
-
- (ClassObject) initialize(namespace, name, *args, &block)
constructor
Creates a new class object in
namespace
withname
. -
- (Boolean) is_exception?
Whether or not the class is a Ruby Exception.
-
- (Array<MethodObject>) meths(opts = {})
Returns the list of methods matching the options hash.
Constructor Details
- (ClassObject) initialize(namespace, name, *args, &block)
Creates a new class object in namespace
with name
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/yard/code_objects/class_object.rb', line 12 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class YARD::CodeObjects::Base
Instance Attribute Details
- (Hash) aliases (readonly) Originally defined in class NamespaceObject
A hash containing two keys, :class and :instance, each containing a hash of objects and their alias names.
- (Hash) attributes (readonly) Originally defined in class NamespaceObject
A hash containing two keys, class and instance, each containing the attribute name with a { :read, :write } hash for the read and write objects respectively.
- (Docstring) base_docstring (readonly) Originally defined in class Base
The non-localized documentation string associated with the object
- (Base?) child(opts = {}) Originally defined in class NamespaceObject
Looks for a child that matches the attributes specified by
opts
.
- (Array<Base>) children (readonly) Originally defined in class NamespaceObject
The list of objects defined in this namespace
- (Hash) class_attributes Originally defined in class NamespaceObject
Only the class attributes
- (Array<ModuleObject>) class_mixins (readonly) Originally defined in class NamespaceObject
Class mixins
- (Array<ConstantObject>) constants(opts = {}) Originally defined in class NamespaceObject
Returns all constants in the namespace
- (Array<ClassVariableObject>) cvars Originally defined in class NamespaceObject
Returns class variables defined in this namespace.
- (Boolean) dynamic Originally defined in class Base
Marks whether or not the method is conditionally defined at runtime
- (Array<String>) files (readonly) Originally defined in class Base
The files the object was defined in. To add a file, use #add_file.
- (Array<String>) groups Originally defined in class NamespaceObject
Returns a list of ordered group names inside the namespace
- (Array<ConstantObject>) included_constants Originally defined in class NamespaceObject
Returns constants included from any mixins
- (Object) included_meths(opts = {}) Originally defined in class NamespaceObject
Returns methods included from any mixins that match the attributes
specified by opts
. If no options are specified, returns all
included methods.
- (Hash) instance_attributes Originally defined in class NamespaceObject
Only the instance attributes
- (Array<ModuleObject>) instance_mixins (readonly) Originally defined in class NamespaceObject
Instance mixins
- (Array<MethodObject>) meths(opts = {}) Originally defined in class NamespaceObject
Returns all methods that match the attributes specified by
opts
. If no options are provided, returns all methods.
- (Array<ModuleObject>) mixins(*scopes) Originally defined in class NamespaceObject
Returns for specific scopes. If no scopes are provided, returns all mixins.
- (NamespaceObject) namespace Also known as: parent Originally defined in class Base
The namespace the object is defined in. If the object is in the top level namespace, this is Registry.root
- (String) signature Originally defined in class Base
The one line signature representing an object. For a method, this will be of the form “def meth(arguments…)”. This is usually the first source line.
- (Symbol) source_type Originally defined in class Base
Language of the source code associated with the object. Defaults to
:ruby
.
- (ClassObject) superclass
The YARD::CodeObjects::ClassObject that this class object inherits from in Ruby source.
7 8 9 |
# File 'lib/yard/code_objects/class_object.rb', line 7 def superclass @superclass end |
- (Symbol) visibility Originally defined in class Base
Returns the visibility of an object (:public, :private, :protected)
Instance Method Details
- (Array<ConstantObject>) constants(opts = {})
Returns the list of constants matching the options hash.
98 99 100 101 |
# File 'lib/yard/code_objects/class_object.rb', line 98 def constants(opts = {}) opts = SymbolHash[:inherited => true].update(opts) super(opts) + (opts[:inherited] ? inherited_constants : []) end |
- (Array<NamespaceObject>) inheritance_tree(include_mods = false)
Returns the inheritance tree of the object including self.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/yard/code_objects/class_object.rb', line 42 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 |
- (Array<ConstantObject>) inherited_constants
Returns only the constants that were inherited.
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/yard/code_objects/class_object.rb', line 106 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 |
- (Array<MethodObject>) inherited_meths(opts = {})
Returns only the methods that were inherited.
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/yard/code_objects/class_object.rb', line 76 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 |
- (Boolean) is_exception?
Whether or not the class is a Ruby Exception
32 33 34 |
# File 'lib/yard/code_objects/class_object.rb', line 32 def is_exception? inheritance_tree.reverse.any? {|o| BUILTIN_EXCEPTIONS_HASH.has_key? o.path } end |
- (Array<MethodObject>) meths(opts = {})
Returns the list of methods matching the options hash. Returns all methods if hash is empty.
63 64 65 66 67 68 69 70 71 |
# File 'lib/yard/code_objects/class_object.rb', line 63 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 |