> Could you share your method wrapping code? It seems to be something
> like what I intended to write.

Um, sure.  Except that just looking closely at this part of my system
(which I am not using for anything important) I notice it is utterly
broken.  The problem is that the persistence layer needs to remember
which objects the commands were for exactly because the object ids
will be different next time they are Marshal.load -ed.  And there is
no way of doing that implemented at present in Mnemonic.

This is one way to wrap method calls anyway.  Note that I am careful
to not make any singleton methods - these cannot be marshaled.

# Need recent Ruby
# Command module - sends any method calls through the persisted object
# note that include Command should be the last line (not first) in 
# your class
module Command
  class <<self
    def included(klass)
      klass.instance_methods.each {|m|
        eval %{
          klass.class_eval {
            alias_method :cmdnew_#{m}, :#{m}
            def #{m}(*args, &block)
              Persisted.thing.execute(self.id, :cmdnew_#{m}, *args,
&block)
            end
          }
        }
      }
    end
  end
end

Assuming you have a persisted thing like this:

# this is the persisted object
# all commands come through here
class Thing
#...
  def execute(objid, method, *args, &block)
    ObjectSpace._id2ref(objid).send(method, *args, &block)
  end
end

# this class is for convenience only - could use a global variable too
class Persisted
  include Singleton
  attr_reader :x
  def initialize
    @x = Mnemonic.new(Thing.new, "thingstore", "execute")
  end
  def Persisted.thing
    Persisted.instance.x
  end
end

Any classes that include Command at the bottom will have all their
method calls persisted.

Except, as I say, it won't work because we don't know which objects
were which the next time we load up the commands.  Creating objects is
not deterministic - they come with a different id each time.

Tricky.

/haldane