"Dan Doel" <djd15 / po.cwru.edu> schrieb im Newsbeitrag
news:401EB68A.80807 / po.cwru.edu...
> Well, here -- http://www.rubycentral.com/ref/ref_c_string.html -- is
> the reference for the Ruby String class.
>
> The first thing that comes to mind is going through the list, finding
> destructive methods, and overriding them in your subclass with a call
> to some update function, like so:
>
> class String
>     def chop!
>        super
>
>        update
>     end
>
>     # ...
>
>     def update
>        # invalidate the cache somehow
>     end
>
>     # ...
> end

Just keep in mind to preserve the return values like in

def chop!
  result = super
  update
  result
end

The other thing is constness...  I feel, that - apart from freeze - Ruby is
not so well suited to differentiating between const and non const instances.
There are too many methods one has to take care of (just think of
instance_eval and instance_variable_get).  And even languages that are
better suited to this task (C++ to name one) have problems of their own with
constness...

Kind regards

    robert