Module: ObjectSpace

Defined in:
padrino-support/lib/padrino-support/core_ext/object_space.rb

Class Method Summary collapse

Class Method Details

.classes(&block) ⇒ Object

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


14
15
16
17
18
# File 'padrino-support/lib/padrino-support/core_ext/object_space.rb', line 14

def classes(&block)
  warn 'Warning! ObjectSpace.classes will be removed in Padrino 0.14'
  require 'padrino-core/reloader'
  Padrino::Reloader::Storage.send(:object_classes, &block)
end

.new_classes(snapshot) ⇒ Object

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)


30
31
32
33
34
# File 'padrino-support/lib/padrino-support/core_ext/object_space.rb', line 30

def new_classes(snapshot)
  warn 'Warning! ObjectSpace.new_classes will be removed in Padrino 0.14'
  require 'padrino-core/reloader'
  Padrino::Reloader::Storage.send(:new_classes, snapshot)
end