From: michael libby Date: 2002-10-30T11:05:19+09:00 Subject: Re: executing a proc passed as an argument? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 29 October 2002 19:36, Alan (Ursus Major) wrote: > class Callback > > def initialize (v, &m) > @cb = m #store a callback method > @v = v #store an argument to pass the method > end > > def exe > # @cb(@v) #execute the stored method (not this way!) @cb.call(@v) #invokes method stored in @cb with @v as argument > p "called exe, value = #{@v}" #stored the value, and > p "stored method = #{@cb}" #maybe the proc? > end > end > > x = Callback.new("a value", &proc{|v| p v}) x = Callback.new("a value"){|v| p v} #much prettier, imho > x.exe Hope this helps. -michael Michael C. Libby x@ichimunki.com http://www.ichimunki.com/ http://www.ichimunki.com/public_key.txt -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9vz4t4ClW9KMwqnMRAinlAJ4rCuI7h5CX0+R6pXuC9qYp43N28gCfeX3a 7Hi9yK/+7XvHtdRiuV7Rp9c= =NuZX -----END PGP SIGNATURE-----