Mauricio FernáĪdez alias batsman [mailto:batsman.geo / yahoo.com] brilliantly
replied:

> > However, I was stuck on "how does one know what methods
> were passed".
> > I want to do this so I can say (especially to my son), "See son, it
> > (the dog) got what you asked for. Next, we will now let it 
> do what we
> > asked..."... I thought this was possible since there is a
> > method_missing() method wc knows the method passed 
> (-unfortunately it
> > is missing :-)..
> 
> You could simulate that with some meta-programming magic
> involving alias_method and method_added, but I wouldn't show 
> that code to your son ;)
> 
> batsman@tux-chan:/tmp$ expand -t2 e.rb
> 
> # keep this secret :P
> module MethodCalledMagic
>   def method_added(id)
>     @level ||= 0
>     return if @level == 1
>     @level += 1
>     alias_method "_real_#{id}", id
>     module_eval <<-EOF
>       def #{id}(*a,&b)
>         puts "You called #{self.inspect}##{id}"
>         _real_#{id}(*a,&b)
>       end
>     EOF
>     @level -= 1
>   end
> end
> 
> # this is what your son sees
> class Dog
>   extend MethodCalledMagic
> end
> 
> d = Dog.new
> class Dog
>   def foo; puts "the dog does foo" end
>   def bar; puts "the dog does bar" end
> end
> 
> d.foo
> d.bar
> 
> batsman@tux-chan:/tmp$ ruby e.rb
> You called Dog#foo
> the dog does foo
> You called Dog#bar
> the dog does bar

Wow. That was close. However it does not do the "unknown methods".

Consider it if I undef bar...

>ruby e.rb
You called Dog#foo
the dog does foo
a2.rb:30: undefined method `bar' for #<Dog:0x27769a0> (NoMethodError)

I would prefer the output to be:
You called Dog#foo
the dog does foo
You called Dog#bar
a2.rb:30: undefined method `bar' for #<Dog:0x27769a0> (NoMethodError)

Is this possible?

kind regards -botp