Class: Ruby::Reflection

Inherits:
Object
  • Object
show all
Includes:
AbstractReflection
Defined in:
lib/ruby/reflection.rb,
lib/ruby/reflection/mirror.rb,
lib/ruby/reflection/class_mirror.rb,
lib/ruby/reflection/field_mirror.rb,
lib/ruby/reflection/thread_mirror.rb,
lib/ruby/reflection/object_mirror.rb,
lib/ruby/reflection/field_mirror/constant_mirror.rb,
lib/ruby/reflection/field_mirror/class_variable_mirror.rb,
lib/ruby/reflection/field_mirror/instance_variable_mirror.rb

Defined Under Namespace

Classes: ClassMirror, ClassVariableMirror, ConstantMirror, FieldMirror, InstanceVariableMirror, Mirror, ObjectMirror, ThreadMirror

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AbstractReflection

included, #reflect_object

Class Method Details

.codebaseObject



12
13
14
# File 'lib/ruby/reflection.rb', line 12

def self.codebase
  nil.class
end

.reflect(ignored) ⇒ Object



16
17
18
# File 'lib/ruby/reflection.rb', line 16

def self.reflect(ignored)
  self.new
end

Instance Method Details

#classesObject



24
25
26
# File 'lib/ruby/reflection.rb', line 24

def classes
  instances_of(Class)
end

#engineObject



48
49
50
# File 'lib/ruby/reflection.rb', line 48

def engine
  RUBY_ENGINE
end

#instances_of(klass) ⇒ Object



28
29
30
# File 'lib/ruby/reflection.rb', line 28

def instances_of(klass)
  mirrors ObjectSpace.each_object(klass).select {|obj| obj.class == klass }
end

#modulesObject



20
21
22
# File 'lib/ruby/reflection.rb', line 20

def modules
  instances_of(Module)
end

#object_by_id(id) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/ruby/reflection.rb', line 32

def object_by_id(id)
  if obj = ObjectSpace._id2ref(id)
    Mirror.reflect obj
  else
    nil
  end
end

#platformObject



44
45
46
# File 'lib/ruby/reflection.rb', line 44

def platform
  RUBY_PLATFORM
end

#threadsObject



40
41
42
# File 'lib/ruby/reflection.rb', line 40

def threads
  instances_of(Thread)
end

#versionObject



52
53
54
# File 'lib/ruby/reflection.rb', line 52

def version
  Object.const_get("#{RUBY_ENGINE.upcase}_VERSION")
end