"Hugh Sasse Staff Elec Eng" <hgs / dmu.ac.uk> wrote

> How might I add some instance variables to an existing class, such
> as String, and have them initialized properly?
.....

If you are working in cvs you can do this easily be redefining allocate.
Note
that String.allocate is not inherited from Object.allocate - i.e. replacing
__allocate with super is not a good idea.

class String
    attr_accessor :pos
    class << self
        alias __allocate allocate
        def allocate
            (res = __allocate).pos = 0
            return res
        end
        private :__allocate
    end
end

/Christoph