J
John W. Long
Is there a way to tell when a destructive method has been called? I've
created a subclass of String to represent a URL. It has handy methods
for extracting parts of the string like the host, port, path, or query
(yes I know about URI). I'd like to cache the results of calling my
extract methods unless the string has changed, in which case I'll
extract and return the correct value again.
The only way I can think of to tell when the string has changed is to
dup in the initialize method and compare with self on every method
call. Are there other options?
created a subclass of String to represent a URL. It has handy methods
for extracting parts of the string like the host, port, path, or query
(yes I know about URI). I'd like to cache the results of calling my
extract methods unless the string has changed, in which case I'll
extract and return the correct value again.
The only way I can think of to tell when the string has changed is to
dup in the initialize method and compare with self on every method
call. Are there other options?