On Wed, Oct 16, 2002 at 10:43:05PM +0900, Eugene Zaikonnikov wrote:
> Hello,
> 
> Is there a way to hook on invocation of *any* instance method of an
> object?
> 
> My first attempt was to override the send method:
> 
> class Foo
>     #just ban them
>     def send(symbol, *args)
> 	puts "blocked"
>     end
> end
> 
> It works when I do:
> 
> foo = Foo.new
> foo.send :something
> 
> But it has no effect on "conventional" method invocations. It seems
> that send is not a part of the built-in method dispatch procedure.
> 
> I want such functionality to implement 'write barriers' for certain
> objects. The idea was to track invocation of writer methods and notify
> object's observer of changes. If this is achievable by other means,
> any hints will be greatly appreciated.

Delegation maybe?

The "barrier keeper" object checks in method_missing whether a method
will modify the object or not, notifies the observers if so, and delegates
the actual work to another object (the one being observed).

The "actual" object would have to provide a list of the methods for which
notification is needed and what action to perform (possibly via a Proc).

-- 
 _           _                             
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
	Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Turn right here. No! NO! The OTHER right!