From: Michael 'entropie' Trommer Date: 2006-01-03T04:56:47+09:00 Subject: Re: About blocks --IS0zKkzwUGydFO0o Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable * dblack@wobblini.net (dblack@wobblini.net) wrote: > Hi -- >=20 > On Mon, 2 Jan 2006, Surgeon wrote: >=20 > >Hi, > > > >(This question might be answered previously. If so, I apologize.) > > > >Can we *ALWAYS* use plain methods instead of blocks? Yes, sometimes > >using a block may be obviously better than using a method but I mean, > >are there any situations in which the *ONLY* solution is to use a block > >rather than a method? May someone be forced to use only and only a > >block? I ask this because I am not very intelligent and I am not sure > >that I will thoroughly understand the "block" concept. >=20 > You don't really use methods instead of blocks; you use methods -- > that is, you call methods -- with or without providing a code block > for a given method call. >=20 > The block is part of the method call syntax, along with the method > name and the argument list. Whether or not it's mandatory is up to > the method (as with arguments). For example: >=20 > def x > end >=20 > def y > yield > end >=20 > def z > yield if block_given? > end >=20 > x # OK -- no block expected or given > x { puts "code block" } # block OK but ignored >=20 > y # error, because no block to yield to > y { puts "code block" } # OK >=20 > z # OK -- no yield will be attempted > z { puts "code block" } # also OK, and block will execute >=20 >=20 > David really intresting lecture! >=20 > --=20 > David A. Black > dblack@wobblini.net >=20 > "Ruby for Rails", from Manning Publications, coming April 2006! > http://www.manning.com/books/black >=20 So long -- Michael 'entropie' Trommer; http://ackro.org ruby -e "0.upto((a=3D'njduspAhnbjm/dpn').size-1){|x| a[x]-=3D1}; p 'mailto:= '+a" --IS0zKkzwUGydFO0o Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iD8DBQFDuYVuBBd8ye5RguQRAgxNAJ9uWojyehmgGuHCTxCeJHEy65Zg8ACgtOd2 uN72Zgflz66OlQQ3yN09hTg= =t+4+ -----END PGP SIGNATURE----- --IS0zKkzwUGydFO0o--