Class: Class
Instance Method Summary collapse
-
#ancestor?(klass) ⇒ Boolean
(also: #parent?)
Check whether the class has the parent ‘klass’.
-
#instances ⇒ Object
Get all instances of this class that exist in ObjectSpace.
Instance Method Details
#ancestor?(klass) ⇒ Boolean Also known as: parent?
Check whether the class has the parent ‘klass’.
Example: Module.has_parent?(Object) #=> true
Returns: True or false
18 19 20 |
# File 'lib/extra/class.rb', line 18 def ancestor?(klass) ancestors[1..-1].include? klass end |
#instances ⇒ Object
Get all instances of this class that exist in ObjectSpace.
Example: Module.instances #=> [Marshal, ObjectSpace, GC, Math, ...]
Returns: Array
8 9 10 |
# File 'lib/extra/class.rb', line 8 def instances objects = []; ObjectSpace.each_object(self) { |obj| objects << obj }; objects end |