Class: Object

Inherits:
BasicObject
Defined in:
lib/goat/extn.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.superclasses(upto = Object) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/goat/extn.rb', line 44

def self.superclasses(upto=Object)
  cs = []
  c = self
  start = self

  while c
    cs << c
    return cs if c == upto
    raise "#{start.inspect} isn't in the hierachy of #{upto}" if c == Object && upto != Object

    c = c.superclass
  end
end

Instance Method Details

#glimpse(n = 100) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/goat/extn.rb', line 65

def glimpse(n=100)
  ins = self.inspect
  if ins =~ />$/ && ins.size > n
    "#{ins[0..n]}...>"
  else
    ins
  end
end

#subclass_of?(cls) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
# File 'lib/goat/extn.rb', line 58

def subclass_of?(cls)
  self == cls || \
    (self == Object ? \
     false : \
     (self.superclass && self.superclass != self && self.superclass.subclass_of?(cls)))
end