Class Class
In: lib/facets/core/facets/module/revise.rb
lib/facets/core/facets/class/descendants.rb
lib/facets/core/facets/class/pathize.rb
lib/facets/core/facets/class/subclasses.rb
lib/facets/core/facets/class/to_proc.rb
lib/facets/core/facets/class/methodize.rb
Parent: Object

Methods

Public Instance methods

List all descedents of this class.

  class A ; end
  class B < A; end
  class C < A; end
  A.descendants  #=> [B,C]

You may also limit the generational distance the subclass may be from the parent class.

  class X ; end
  class Y < X; end
  class Z < Y; end
  X.descendants    #=> [Y,Z]
  X.descendants(1) #=> [Y]

NOTE: This is a intensive operation. Do not expect it to be very fast.

[Source]

# File lib/facets/core/facets/class/descendants.rb, line 23
  def descendants(generations=-1)
    descendants = []
    subclasses.each do |k|
      descendants << k
      if generations != 1
        descendants.concat(k.descendants(generations - 1))
      end
    end
    descendants
  end

Translate a class name to a suitable method name.

  module ::Example
    class MethodizeExample
    end
  end

  Example::MethodizeExample.methodize  #=> "example__methodize_example"

[Source]

# File lib/facets/core/facets/class/methodize.rb, line 14
  def methodize
    name.methodize
  end

Converts a class name to a unix path.

  module ::Example
    class PathizeExample
    end
  end

  Example::PathizeExample.pathize  #=> "example/pathize_example"

[Source]

# File lib/facets/core/facets/class/pathize.rb, line 14
  def pathize
    name.pathize
  end

Returns an array with the direct children of self.

  Integer.subclasses # => [Fixnum, Bignum]

[Source]

# File lib/facets/core/facets/class/subclasses.rb, line 17
    def subclasses
      list = []
      ObjectSpace.each_object(Class) do |c|
        list.unshift c if c.superclass == self
      end
      list.uniq
    end

Convert instatiation of a class into a Proc.

  class Person
    def initialize(name)
      @name = name
    end

    def inspect
      @name.to_str
    end
  end

  persons = %w(john bob jane hans).map(&Person)

  persons.map{ |p| p.inspect }  #=> ['john', 'bob', 'jane', 'hans']

CREDIT: Daniel Schierbeck

[Source]

# File lib/facets/core/facets/class/to_proc.rb, line 20
  def to_proc
    proc{|*args| new(*args)}
  end

[Validate]