Class: Object

Inherits:
BasicObject
Defined in:
lib/as_code.rb,
lib/classtree.rb,
ext/generate_cached.rb

Instance Method Summary collapse

Instance Method Details

#as_code(indent = 0) ⇒ Object



342
343
344
345
# File 'lib/as_code.rb', line 342

def as_code(indent=0)
  # TODO: this won't work for many objects
  "#{'  '*indent}#{self.inspect}"
end

#classtree(s = '', prefix = '', obj = self, graphed = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/classtree.rb', line 4

def classtree(s = '', prefix = '', obj=self, graphed={})
  # if Module == obj.class.class then
  #   s << "included module "
  # elsif obj.singleton? then
  #   s << "singleton class "
  # elsif Class === obj then
  #   s << "class "
  # end
  s << "#{obj}"
  if graphed[obj] then
    s << " (*)\n"
    return s
  end
  s << "\n"
  graphed[obj] = true
  return if Kernel == obj
  subtree = (Module === obj) && (obj.real_superclass)
  s << "#{prefix}#{subtree ? '|-' : '+-'}class = "
  classtree(s, prefix + (subtree ? '| ' : '  '), obj.real_class, graphed)
  if subtree then
    s << "#{prefix}+-super = "
    classtree(s, prefix + '  ', obj.real_superclass, graphed)
  end
  return s
end

#has_singleton?Boolean

Return true if this object has a singleton class.

Returns:



2313
2314
2315
2316
# File 'ext/nodewrap.c', line 2313

VALUE has_singleton(VALUE self)
{
  return FL_TEST(RBASIC(self)->klass, FL_SINGLETON) ? Qtrue : Qfalse;
}

#real_classClass

Return the object’s first immediate ancestor; this may be the object’s class, its singleton class, or a module singleton.

Returns:



2290
2291
2292
2293
# File 'ext/nodewrap.c', line 2290

VALUE real_class(VALUE self)
{
  return RBASIC(self)->klass;
}

#singleton?Boolean

Return true if this object is a singleton (that is, it has the FL_SINGLETON flag set).

Returns:



2302
2303
2304
2305
# File 'ext/nodewrap.c', line 2302

VALUE is_singleton(VALUE self)
{
  return FL_TEST(self, FL_SINGLETON) ? Qtrue : Qfalse;
}

#singleton_classClass

Return the object’s singleton class. Creats a new singleton class for the object if it does not have one. See RCR#231.

Returns:



2325
2326
2327
2328
# File 'ext/nodewrap.c', line 2325

VALUE singleton_class(VALUE self)
{
  return rb_singleton_class(self);
}