class Class

Public Instance Methods

hierarchy() click to toggle source

Returns a tree-like Hash structure of all descendants.

Examples

require 'socket'
IO.hierarchy
#=> {BasicSocket=>{UNIXSocket=>{UNIXServer=>{}}, IPSocket=>{UDPSocket=>{}, TCPSocket=>{TCPServer=>{}}}, Socket=>{}}, File=>{}}
# File core_extensions/class.rb, line 13
def hierarchy
  subclasses.each_with_object({}) { |k, h| h[k] = k.hierarchy }
end
leaf_subclasses() click to toggle source

Returns an Array of all descendants which have no subclasses.

Examples

require 'socket'
BasicSocket.leaf_subclasses
#=> [Socket, UNIXServer, UDPSocket, TCPServer]
# File core_extensions/class.rb, line 35
def leaf_subclasses
  descendants.select { |d| d.subclasses.empty? }
end
lineage() click to toggle source

Returns an Array of all superclasses.

Examples

require 'socket'
TCPServer.lineage
#=> [TCPSocket, IPSocket, BasicSocket, IO, Object, BasicObject]
# File core_extensions/class.rb, line 24
def lineage
  superclass.nil? ? [] : superclass.lineage.unshift(superclass)
end