From: Edward Faulkner Date: 2006-03-02T00:50:05+09:00 Subject: Re: Indexing system - ruby newbie --SUOF0GtieIMvvwua Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Mar 02, 2006 at 12:14:47AM +0900, Adam Groves wrote: > But I'm stuck here. >=20 > (1...n).inject("A") { |curr, i| curr.succ} >=20 > I still can't quite get my head around blocks beyond .each do |x| #inject is one of the basic tools of functional programming. That's why it seems hard. It's a very different way of thinking. And also very powerful. That said, I think this case is a completely gratuitious use of inject. The tipoff is that the argument "i" is completely ignored. I like this much better: def letter(n) return '_' if n=3D=3D0 n=3D=3D1 ? "A" : letter(n-1).succ end regards, Ed --SUOF0GtieIMvvwua Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFEBcKbnhUz11p9MSARAkLZAJ4kUYU2JF1MTukPMl/kE4xoEVM/AACfW4ij Q1/1uQTDtcyTEaTm0by1FdE= =YuNn -----END PGP SIGNATURE----- --SUOF0GtieIMvvwua--