### Home Classes Methods

### In Files

- lib/facets/objectspace/classes.rb
- lib/facets/objectspace/op_fetch.rb
- lib/facets/objectspace/reflect.rb

### Methods

- ::classes
- ::reflect

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Lazy
- Lazy::Future
- Lazy::Promise
- Lazy::Promise::DIVERGES
- Lazy::PromiseSafe
- Enumerable
- Enumerable::Recursor
- Method
- Method::Composition
- Module
- Module::InstanceFunction
- Array
- Binding
- Class
- Comparable
- Denumerable
- Denumerator
- Dir
- Enumerator
- Exception
- Facets
- FalseClass
- File
- FileTest
- Fixnum
- Float
- Functor
- Hash
- Indexable
- Instance
- Integer
- Kernel
- MatchData
- NA
- NilClass
- Numeric
- Object
- ObjectSpace
- Proc
- Process
- Range
- Regexp
- String
- Struct
- Symbol
- Time
- TrueClass
- UnboundMethod

No matching classes.

# ObjectSpace

### Public Class Methods

classes() click to toggle source

@return <Array> All the classes in the object space.

    # File lib/facets/objectspace/classes.rb, line 4
    def self.classes
      klasses = []
      each_object(Class){|o| klasses << o}
      klasses
    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("object").object_id

There is also a global short-cut for this method to ease meta-programming with it.

    $ref["object"].class

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)+ ...

    "object".as(Kernel).object_id

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

    # File lib/facets/objectspace/reflect.rb, line 31
    def self.reflect(obj)
      ## TODO: use this after 1.8.6 support discontinued
      ## Functor.new do |op, *a, &b|
      ##   Kernel.instance_method(op).bind(obj).call(*a, &b)
      ## end
      Reflector.new(obj)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.