From: Dana Merrick Date: 2008-06-12T05:13:02+09:00 Subject: Re: array collect - nil can't be coerced into Float (TypeErr --------------enig4007035DB9F4B1FFDED9AF9A Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Now, to make it a little more Ruby-y: class MyArray def count() a =3D [1,2,3] b =3D [0.5,0.25] result =3D Array.new a.each do |i| result << b.collect {|x| x * i} end return result end end number =3D MyArray.new puts number.count -Dana Jason Lillywhite wrote: > I will settle with this: >=20 > class MyArray > def count > a =3D [1,2,3] > b =3D [0.5,0.25] > num =3D a.length > i =3D 0 > c =3D [] > while i < num do > c << b.collect {|x| x * a[i]} > i +=3D 1 > end > puts c > end > end >=20 > number =3D MyArray.new > number.count >=20 >=20 > that way it does matter if I change the length of a. >=20 > thanks again. >=20 --=20 Dana Merrick - System Administrator Integrated Computer Solutions, Inc. 54B Middlesex Tpke, Bedford, MA 01730 617.621.0060 x112 - http://www.ics.com --------------enig4007035DB9F4B1FFDED9AF9A Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Darwin) iEYEARECAAYFAkhQMd8ACgkQ7b+8UB5G/wMBdwCgjkH/mYuWnKlLuDUVKOijrA4I 54gAn3uC0T4oy4REOOufaRaunc4RiKrA =/mUm -----END PGP SIGNATURE----- --------------enig4007035DB9F4B1FFDED9AF9A--