Class: Class

Inherits:
Object show all
Defined in:
lib/kyanite/general/classutils.rb

Overview

Class Utils

Kyanite definitions

Class, Symbol, String

Kyanite tests and examples

TestKyaniteClassutils

Usage

require ‘kyanite/general/classutils’

Added from Facets Class:

descendants(generations=-1))

List all descedents of this class.

Class Utils collapse

Instance Method Details

#<=>(other) ⇒ Integer

Comparison operator (alphabetical)

Returns:



25
26
27
# File 'lib/kyanite/general/classutils.rb', line 25

def <=>(other) 
    ( ( self.to_s ) <=> ( other.to_s ) )
end

#=~(other) ⇒ Boolean

Fuzzy comparison of two classes (useful for tests)

Returns:

  • (Boolean)


32
33
34
35
36
37
# File 'lib/kyanite/general/classutils.rb', line 32

def =~(other)
  return true   if self == other
  return true   if self.descendants.include?(other)
  return true   if other.descendants.include?(self)
  return false
end

#to_classClass

Converts to a class, the reverse of to_classname

Defined for classes Class, Symbol, String. Accepts both CamelCase and down_case.

Tests and examples here.

Returns:



40
41
42
# File 'lib/kyanite/general/classutils.rb', line 40

def to_class 
  self
end

#to_classnameString

Converts to a class name , the reverse of to_class.

classes Class, Symbol, String. The class name will contain only lowercase letters.

'MyModul::MyClass'  =>  'my_class'

Tests and examples here.

Returns:



46
47
48
# File 'lib/kyanite/general/classutils.rb', line 46

def to_classname
  self.to_s.demodulize.underscore
end