Module: ObjectSpace
- Defined in:
- lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/support_lite.rb
Class Method Summary collapse
-
.classes(&block) ⇒ Object
Returns all the classes in the object space.
-
.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.
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
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/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) ⇒ 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)
152 153 154 155 156 157 158 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/support_lite.rb', line 152 def new_classes(snapshot) self.classes do |klass| if !snapshot.include?(klass) klass end end end |