ObjectSpace

Public Class Methods

classes() click to toggle source

@return All the classes in the object space.

   # File lib/core/facets/objectspace/classes.rb, line 4
4:   def self.classes
5:     klasses = []
6:     each_object(Class){|o| klasses << o}
7:     klasses
8:   end
reflect(obj) click to toggle source

Reflection ensures that information about an object is actual according to Ruby’s Kernel definitions, just in case such methods have been overridden.

 ObjectSpace.reflect(obj).id

Typically theis method will be used to gather the object’s id, as in the example given, or it’s class, but any Kernel method can be used.

Care should be taken in utilizing this technique. In most cases it is not needed, but in certain cases is useful for improving the robustness of meta-programming solutions.

Note that this is also equivalent to using +as(Kernel)+:

  obj.as(Kernel).id

But obviously, in this case there is the risk that # has be overridden too.

    # File lib/core/facets/objectspace/reflect.rb, line 33
33:   def self.reflect(obj)
34:     Functor.new do |meth, *a, &b|
35:       Kernel.instance_method(meth).bind(obj).call(*a, &b)
36:     end
37:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.