class Object

Object

These methods are copied directly from _why's metaid.rb. See: whytheluckystiff.net/articles/seeingMetaclassesClearly.html

Constants

NOMETACLASS

An Array of classes which do not have metaclasses.

Public Instance Methods

class_def(name, &blk) click to toggle source

Add a class method called name for the current object's class. This isn't so special but it maintains consistency with meta_def.

# File lib/attic.rb, line 52
def class_def name, &blk
  class_eval { define_method name, &blk }
end
meta_def(name, &blk) click to toggle source

Add an instance method called name to metaclass for the current object. This is useful because it will be available as a singleton method to all subclasses too.

# File lib/attic.rb, line 46
def meta_def name, &blk
  meta_eval { define_method name, &blk }
end
meta_eval(&blk;) click to toggle source

Execute a block +&blk+ within the metaclass of the current object.

# File lib/attic.rb, line 41
def meta_eval &blk; metaclass.instance_eval &blk; end
metaclass() click to toggle source

A convenient method for getting the metaclass of the current object. i.e.

class << self; self; end;

NOTE: Some Ruby class do not have meta classes (see: NOMETACLASS). For these classes, this method returns the class itself. That means the instance variables will stored in the class itself.

# File lib/attic.rb, line 32
def metaclass
  if !self.metaclass?
    raise NoMetaClass, self
  else
    class << self; self; end; 
  end
end
metaclass?() click to toggle source
# File lib/attic.rb, line 20
def metaclass?
  !NOMETACLASS.member?(self.class)
end
metameta_def(name, &blk) click to toggle source
# File lib/attic.rb, line 66
def metameta_def name, &blk
  metameta_eval { define_method name, &blk }
end
metameta_eval(&blk;) click to toggle source
# File lib/attic.rb, line 64
def metameta_eval &blk; metametaclass.instance_eval &blk; end
metametaclass() click to toggle source

A convenient method for getting the metaclass of the metaclass i.e.

self.metaclass.metaclass
# File lib/attic.rb, line 62
def metametaclass; self.metaclass.metaclass; end
nometaclass?() click to toggle source
# File lib/attic.rb, line 16
def nometaclass?
  NOMETACLASS.member?(self)
end