Class: YARD::CodeObjects::ClassObject

Inherits:
NamespaceObject show all
Defined in:
lib/yard/code_objects/class_object.rb

Instance Attribute Summary

Instance Method Summary

Methods inherited from Base

#==, ===, #[], #[]=, #add_file, #dynamic?, #file, #format, #format_source, #has_tag?, #inspect, #line, #method_missing, #name, new, #parent, #parent=, #path, #relative_path, #root?, #sep, #tag, #tags, #to_s, #type

Constructor Details

- (ClassObject) initialize(namespace, name, *args, &block)

Creates a new class object in namespace with name

See Also:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/yard/code_objects/class_object.rb', line 10

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

- (ClassObject) superclass

The ClassObject that this class object inherits from in Ruby source.

Returns:

  • (ClassObject) — a class object that is the superclass of this one


5
6
7
# File 'lib/yard/code_objects/class_object.rb', line 5

def superclass
  @superclass
end

Instance Method Details

- (Array<ConstantObject>) constants(opts = {})

Returns the list of constants matching the options hash.

Parameters:

  • (Hash) opts (defaults to: {}) — the options hash to match

Options Hash (opts):

  • (Boolean) :inherited — default: true — whether inherited constant should be included in the list
  • (Boolean) :included — default: true — whether mixed in constant should be included in the list

Returns:



89
90
91
92
# File 'lib/yard/code_objects/class_object.rb', line 89

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.

Parameters:

  • (Boolean) include_mods (defaults to: false) — whether or not to include mixins in the inheritance tree.

Returns:



40
41
42
43
44
45
46
47
48
49
# File 'lib/yard/code_objects/class_object.rb', line 40

def inheritance_tree(include_mods = false)
  list = (include_mods ? mixins(:instance) : [])
  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 unless m.respond_to?(:inheritance_tree)
    m.inheritance_tree(include_mods)
  end.flatten
end

- (Array<ConstantObject>) inherited_constants

Returns only the constants that were inherited.

Returns:



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/yard/code_objects/class_object.rb', line 97

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.

Returns:



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/yard/code_objects/class_object.rb', line 68

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|
        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

Returns:

  • (Boolean) — whether the object represents a Ruby exception


30
31
32
# File 'lib/yard/code_objects/class_object.rb', line 30

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.

Parameters:

  • (Hash) opts (defaults to: {}) — the options hash to match

Options Hash (opts):

  • (Boolean) :inherited — default: true — whether inherited methods should be included in the list
  • (Boolean) :included — default: true — whether mixed in methods should be included in the list

Returns:



60
61
62
63
# File 'lib/yard/code_objects/class_object.rb', line 60

def meths(opts = {})
  opts = SymbolHash[:inherited => true].update(opts)
  super(opts) + (opts[:inherited] ? inherited_meths(opts) : [])
end