Class: Ruby::Reflection::ClassMirror
Instance Attribute Summary
#reflection
Instance Method Summary
collapse
#instance_variables, #method_dictionary, #namespace, #singleton_instance
#instance_eval, #objects_with_references, #path_to, #target_class, #transitive_closure, #variables
#initialize, #mirrors?, #name, #reflectee
#included, #mirror_class, #new, #reflect, #reflect!, #reflects?, #register_mirror
#target_class, #variables
Instance Method Details
#ancestors ⇒ Object
45
46
47
|
# File 'lib/ruby/reflection/class_mirror.rb', line 45
def ancestors
mirrors @subject.ancestors
end
|
#class_instance_variables ⇒ Object
11
12
13
|
# File 'lib/ruby/reflection/class_mirror.rb', line 11
def class_instance_variables
field_mirrors @subject.instance_variables
end
|
#class_variables ⇒ Object
7
8
9
|
# File 'lib/ruby/reflection/class_mirror.rb', line 7
def class_variables
field_mirrors @subject.class_variables
end
|
#constant(str) ⇒ Object
53
54
55
56
57
58
59
60
|
# File 'lib/ruby/reflection/class_mirror.rb', line 53
def constant(str)
path = str.to_s.split("::")
c = path[0..-2].inject(@subject) {|klass,str| klass.const_get(str) }
field_mirror (c || @subject), path.last
rescue NameError => e
p e
nil
end
|
#constants ⇒ Object
49
50
51
|
# File 'lib/ruby/reflection/class_mirror.rb', line 49
def constants
field_mirrors @subject.constants
end
|
#method(name) ⇒ Object
87
88
89
|
# File 'lib/ruby/reflection/class_mirror.rb', line 87
def method(name)
reflection.reflect @subject.instance_method(name)
end
|
83
84
85
|
# File 'lib/ruby/reflection/class_mirror.rb', line 83
def methods
@subject.instance_methods(false).collect(&:to_s)
end
|
32
33
34
|
# File 'lib/ruby/reflection/class_mirror.rb', line 32
def mixins
mirrors @subject.ancestors.reject {|m| m.is_a? Class }
end
|
#nested_classes ⇒ Object
73
74
75
76
77
78
79
80
81
|
# File 'lib/ruby/reflection/class_mirror.rb', line 73
def nested_classes
nc = @subject.constants.collect do |c|
if @subject.const_defined?(c) and not @subject.autoload?(c)
@subject.const_get(c)
end
end.compact.select {|c| Module === c }
mirrors nc
end
|
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/ruby/reflection/class_mirror.rb', line 62
def nesting
ary = []
@subject.name.split("::").inject(Object) do |klass,str|
ary << klass.const_get(str)
ary.last
end
ary.reverse
rescue NameError => e
[@subject]
end
|
#singleton_class ⇒ Object
24
25
26
|
# File 'lib/ruby/reflection/class_mirror.rb', line 24
def singleton_class
reflection.reflect @subject.singleton_class
end
|
#singleton_class? ⇒ Boolean
28
29
30
|
# File 'lib/ruby/reflection/class_mirror.rb', line 28
def singleton_class?
self.name =~ /^\#<Class:.*>$/
end
|
#source_files ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/ruby/reflection/class_mirror.rb', line 15
def source_files
locations = @subject.instance_methods(false).collect do |name|
method = @subject.instance_method(name)
file = method.source_location if method.respond_to? :source_location
file.first if file
end
locations.compact.uniq
end
|
#subclasses ⇒ Object
40
41
42
43
|
# File 'lib/ruby/reflection/class_mirror.rb', line 40
def subclasses
l = ObjectSpace.each_object(Class).select {|a| a.superclass == @subject }
mirrors l
end
|
#superclass ⇒ Object
36
37
38
|
# File 'lib/ruby/reflection/class_mirror.rb', line 36
def superclass
reflection.reflect @subject.superclass
end
|