Hi,

I am sorry that I think the whole discussion has advanced to a new
level; but to answer the original question, can't we do a simple thing
like:

$blocked = true
(Foo.new.methods - Object.methods).each do |met|
  str  = "class Foo\n"
  str << "  alias #{met}_original #{met}\n"
  str << "  def #{met} (*args)\n"
  str << "    if $blocked\n"
  str << "      puts 'blocked'\n"
  str << "    else\n"
  str << "      #{met}_original(*args)"
  str << "    end\n"
  str << "  end\n"
  str << "end"
  eval str
end

?  The code above can easily be modified to pick which methods to block
(by matching "met" with a regexp), to notify the observer, etc.  This is
of course if we don't want to go into some aspect-oriented programming, as
also has been suggested.

Regards,

Bill
============================================================================
Eugene Zaikonnikov <viking / funcall.org> 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.

> --
>   Eugene