Module: ObjectSpace

### Home Classes Methods

### In Files

- lib/padrino-core/support_lite.rb

### Methods

- ::classes
- ::new_classes

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Padrino
- Padrino::Application
- Padrino::ApplicationLoadError
- Padrino::ApplicationSetupError
- Padrino::Cli
- Padrino::Cli::Adapter
- Padrino::Cli::Base
- Padrino::Erubis
- Padrino::Erubis::SafeBufferEnhancer
- Padrino::Erubis::SafeBufferTemplate
- Padrino::Erubis::Template
- Padrino::Filter
- Padrino::Flash
- Padrino::Flash::Helpers
- Padrino::Flash::Storage
- Padrino::Logger
- Padrino::Logger::Colorize
- Padrino::Logger::Extensions
- Padrino::Logger::Rack
- Padrino::Module
- Padrino::Mounter
- Padrino::Mounter::MounterException
- Padrino::Reloader
- Padrino::Reloader::Rack
- Padrino::Rendering
- Padrino::Rendering::ClassMethods
- Padrino::Rendering::InstanceMethods
- Padrino::Rendering::SafeTemplate
- Padrino::Rendering::TemplateNotFound
- Padrino::Router
- Padrino::Routing
- Padrino::Routing::ClassMethods
- Padrino::Routing::InstanceMethods
- Padrino::Routing::Parent
- Padrino::Routing::UnrecognizedException
- Padrino::Server
- Padrino::ShowExceptions
- Padrino::Tasks
- Padrino::Utils
- HttpRouter
- HttpRouter::Node
- HttpRouter::Node::Path
- HttpRouter::Request
- HttpRouter::Route
- Haml
- Haml::Helpers
- Haml::Util
- Sinatra
- Sinatra::Request
- Slim
- Slim::Template
- Tilt
- Tilt::HamlTemplate
- FileSet
- Kernel
- Module
- Object
- ObjectSpace
- PadrinoTasks
- String
- SupportLite

No matching classes.

# ObjectSpace

### Public Class Methods

classes(&block) click to toggle source

Returns all the classes in the object space. Optionally, a block can be passed, for example the following code would return the classes that start with the character "A":

    ObjectSpace.classes do |klass|
      if klass.to_s[0] == "A"
        klass
      end
    end

    # File lib/padrino-core/support_lite.rb, line 125
    def classes(&block)
      rs = Set.new

      ObjectSpace.each_object(Class).each do |klass|
        if block
          if r = block.call(klass)
            # add the returned value if the block returns something
            rs << r
          end
        else
          rs << klass
        end
      end

      rs
    end

new_classes(snapshot) click to toggle source

Returns a list of existing classes that are not included in "snapshot" This method is useful to get the list of new classes that were loaded after an event like requiring a file. Usage:

    snapshot = ObjectSpace.classes
    # require a file
    ObjectSpace.new_classes(snapshot)

    # File lib/padrino-core/support_lite.rb, line 152
    def new_classes(snapshot)
      self.classes do |klass|
        if !snapshot.include?(klass)
          klass
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.