From: Aleksey V Zapparov Date: 2012-07-02T01:22:38+09:00 Subject: Re: Question on Learning Ruby the Hard Way --Sig_/dAk6TZ9kzgx=MGFNeMqJsgx Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Sun, 1 Jul 2012 21:19:53 +0900 Michael Sung wrote: > Hi, I have a question on Exercise 43 of Learning Ruby the Hard Way. >=20 > Specifically, I'm wondering if someone to talk me through what's > happening below. >=20 > def play() > next_room =3D @start >=20 > while true > puts "\n--------" > room =3D method(next_room) > next_room =3D room.call() > end > end >=20 >=20 > I can see that variable next_room is set to instance variable @start. > But how does this "while" loop work? I'm also not familiar with how > "method" and "call" are both used here, as well as the : used in > return (e.g. return :central_corridor) below. Inside loop you are calling `method` instance method, which returns a Method instance, in your case it's `central_corridor`, then you simply calling it with `call()` same as `next_room =3D central_corridor()` at least in the first time in that case. :)) See details here: - http://www.ruby-doc.org/core-1.9.3/Object.html#method-i-method - http://www.ruby-doc.org/core-1.9.3/Method.html --=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_/dAk6TZ9kzgx=MGFNeMqJsgx Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iQEcBAEBAgAGBQJP8HlFAAoJEGRO9nGLm9Y8CokIAJXzWU4qQfm3shV4s2ctb85Q gAa7OVl1EcxP2OSHFQEEfc6+lJVSMLltIEmP0fcuE5zceQkyuU3o81qnNvmo86ao WyCpx6+Xav4bBNKRpBI06WWYc1Gsty0b5d8zr9+Ms8L/gZG/AOoyLynDcf4D/O6M R83WKx1D+C4O1xqGG8Ek4UXCT8v4cyHPVgI3pEpP4o4/tW6o2IEoqDU0mwH+cK0h oB0ptT+Fsfp6noSrh/GttDQBWGvhBRnAgOdlqHAsP1nzjZF7B7f71rjCXzGQCjci 62X5uZDOw9H26ZfP6JhN2LCTqhTWx8bZRecLmbV5k0jQNW4kiDFPA648R8ncRHM= =f6+7 -----END PGP SIGNATURE----- --Sig_/dAk6TZ9kzgx=MGFNeMqJsgx--