class YARD::CodeObjects::NamespaceObject
({ModuleObject}) and classes ({ClassObject}).
The two main Ruby objects that can act as namespaces are modules
A “namespace” is any object that can store other objects within itself.
def child(opts = {})
-
(Base, nil)- the first matched child object, or nil
Other tags:
- Example: Finds a child by name and scope -
def child(opts = {}) if !opts.is_a?(Hash) children.find {|o| o.name == opts.to_sym } else opts = SymbolHash[opts] children.find do |obj| opts.each do |meth, value| break false unless value.is_a?(Array) ? value.include?(obj[meth]) : obj[meth] == value end end end end
def class_attributes
- See: #attributes -
Returns:
-
(Hash)- a list of method names and their read/write objects
def class_attributes attributes[:class] end
def constants(opts = {})
-
(Array- a list of constant objects)
Options Hash:
(**opts)-
:included(Boolean) -- whether or not to include
def constants(opts = {}) opts = SymbolHash[:included => true].update(opts) consts = children.select {|o| o.is_a? ConstantObject } consts + (opts[:included] ? included_constants : []) end
def cvars
-
(Array- a list of class variable objects)
def cvars children.select {|o| o.is_a? ClassVariableObject } end
def included_constants
-
(Array- a list of constant objects)
def included_constants instance_mixins.inject([]) do |list, mixin| if mixin.respond_to? :constants list += mixin.constants.reject do |o| child(:name => o.name) || list.find {|o2| o2.name == o.name } end else list end end end
def included_meths(opts = {})
- See: #meths -
Options Hash:
(**opts)-
:included(Boolean) -- whether to include mixed in -
:scope(Array) -- the, Symbol -
:visibility(Array) -- [:public, :private,, Symbol
def included_meths(opts = {}) opts = SymbolHash[:scope => [:instance, :class]].update(opts) [opts[:scope]].flatten.map do |scope| mixins(scope).inject([]) do |list, mixin| next list if mixin.is_a?(Proxy) arr = mixin.meths(opts.merge(:scope => :instance)).reject do |o| next false if opts[:all] child(:name => o.name, :scope => scope) || list.find {|o2| o2.name == o.name } end arr.map! {|o| ExtendedMethodObject.new(o) } if scope == :class list + arr end end.flatten end
def initialize(namespace, name, *args, &block)
- See: Base#initialize -
def initialize(namespace, name, *args, &block) @children = CodeObjectList.new(self) @class_mixins = CodeObjectList.new(self) @instance_mixins = CodeObjectList.new(self) @attributes = SymbolHash[:class => SymbolHash.new, :instance => SymbolHash.new] @aliases = {} @groups = [] super end
def instance_attributes
- See: #attributes -
Returns:
-
(Hash)- a list of method names and their read/write objects
def instance_attributes attributes[:instance] end
def meths(opts = {})
-
(Array- a list of method objects)
Options Hash:
(**opts)-
:included(Boolean) -- whether to include mixed in -
:scope(Array) -- the, Symbol -
:visibility(Array) -- [:public, :private,, Symbol
Other tags:
- Example: Finds all private and protected class methods -
def meths(opts = {}) opts = SymbolHash[ :visibility => [:public, :private, :protected], :scope => [:class, :instance], :included => true ].update(opts) opts[:visibility] = [opts[:visibility]].flatten opts[:scope] = [opts[:scope]].flatten ourmeths = children.select do |o| o.is_a?(MethodObject) && opts[:visibility].include?(o.visibility) && opts[:scope].include?(o.scope) end ourmeths + (opts[:included] ? included_meths(opts) : []) end
def mixins(*scopes)
-
(Array- a list of mixins)
Parameters:
-
scopes(Array) -- a list of scopes (:class, :instance) to
def mixins(*scopes) return class_mixins if scopes == [:class] return instance_mixins if scopes == [:instance] class_mixins | instance_mixins end