Class: Class

Inherits:
Object show all
Defined in:
lib/extra/class.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


18
19
20
# File 'lib/extra/class.rb', line 18

def ancestor?(klass)
	ancestors[1..-1].include? klass
end

#instancesObject

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