From: Aleksey V Zapparov Date: 2012-07-02T03:22:16+09:00 Subject: Re: Question on Learning Ruby the Hard Way --Sig_/l6fIoFHxcKXO5deO.=58Xhw Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Mon, 2 Jul 2012 01:38:30 +0900 "Jan E." wrote: > Calling "method" with a method name as a Symbol creates a Method > object for this method. This object can then be passed around and > called at any time (by calling the "call" method): >=20 > class A > def f > puts "f called" > end > end >=20 > a =3D A.new > f =3D a.method(:f) #create a Method object for method "f" > p f > f.call() # call Method object (without arguments) >=20 > See > http://ruby-doc.org/core-1.9.3/Object.html#method-i-method > http://ruby-doc.org/core-1.9.3/Method.html Michael, please notice that this Method object is bounded to the object it was initiated from: class Foo def initialize @i =3D 0 end def bar @i +=3D 1 end end o =3D Foo.new m =3D o.method :bar o.bar # =3D> 1 m.call # =3D> 2 m.call # =3D> 3 o.bar # =3D> 4 --=20 Sincerely yours, Aleksey V. Zapparov A.K.A. ixti FSF Member #7118 Mobile Phone: +34 677 990 688 Homepage: http://www.ixti.net JID: zapparov@jabber.ru *Origin: Happy Hacking! --Sig_/l6fIoFHxcKXO5deO.=58Xhw Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iQEcBAEBAgAGBQJP8JVRAAoJEGRO9nGLm9Y8UUQH/0lHVx+a8XLbPkCHuRubwIMF Q0YFKMA/8+4ZIk2NlkpAF9AVgn5ZBlImd5gzH49Muzxvi9C5KDvV+zkjNeRVI386 m2sor0IciObinVg3xAXM4Ox833n/SS1uKcbAdvuYCUGIucFaFv6RWcq1zg14VD8U xfd2YDekQ8ZP/PjXeyHKlZROAjY1dMcaFAzbKyXl4lC08ep9YvCw0Rumm7vIO/YG CoFJWqC6AyjfjrIng2unSKUJlGJhQ3MJXYgpodcGOZ7nkAKftc8FyOPnZ/5wEnmw IfGziQlJnfxI80n46RWkPwz5Z8vBIIDjnKEeY3cfjRPiepPBl57ybIlXRLB4tNY= =9ccy -----END PGP SIGNATURE----- --Sig_/l6fIoFHxcKXO5deO.=58Xhw--