From: "Zachary P. Landau" Date: 2004-01-27T16:40:59+09:00 Subject: Re: nuby: determine method passed and determine the receiver that rec eived the method --IJpNTDwzlM2Ie8A6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable > # keep this secret :P > module MethodCalledMagic > def method_added(id) > @level ||=3D 0 > return if @level =3D=3D 1 > @level +=3D 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 -=3D 1 > end >=20 > def self.extend_object(obj) > obj.send :define_method, :method_missing do |id,*a| > puts "You called #{self.class}##{id}" > super id > end > super > end > end Promise us you will never show this code to anyone who is considering ruby. They will run away screaming halfway through the first method. -- Zachary P. Landau GPG: gpg --recv-key 0x24E5AD99 | http://kapheine.hypa.net/kapheine.asc --IJpNTDwzlM2Ie8A6 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFAFhWmCwWyMCTlrZkRAvCIAJ9p6PuDxVGv4yQR+oeKGhontHPHxQCfQ9vf tTm95yQWHP9BshzaSzHXGII= =g9cK -----END PGP SIGNATURE----- --IJpNTDwzlM2Ie8A6--