From: Roelof Wobben Date: 2012-10-14T00:48:31+09:00 Subject: Re: multiple array problem --_85f45900-c296-43ec-b9ec-534104137ac5_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello=2C Thanks =2C but I only need 1 of the three category but which one is chancin= g. Roelof > Date: Sun=2C 14 Oct 2012 00:43:15 +0900 > From: rubytalk2dave@davearonson.com > Subject: Re: multiple array problem > To: ruby-talk@ruby-lang.org >=20 > On Sat=2C Oct 13=2C 2012 at 7:35 AM=2C Roelof Wobben wrote: >=20 > > category1.article.each do |artikel| > > puts article.name > > end > > > > category2.article.each do |artikel| > > puts article.name > > end > > > > category3.article.each do |artikel| > > puts article.name > > end > > > > But now I have 3 parts of code which are almost the same. > > Is there a way I can make 1 part of code where the category is a variab= le. >=20 > Sure. Make an array out of your 3 arrays: [category1=2C category2=2C > category3]. Then call .each on THAT. E.g.: >=20 > [category1=2C category2=2C category3].each do |category| > category.article.each do |article| > puts article.name > end > end >=20 > Not sure where you're getting category.article from though=3B is > category an instance of some class like Category=2C that has an array > called article? (If so=2C I'd suggest making the name plural to show > it's a collection.) >=20 > Which reminds me=2C watch out for mismatches between human languages. > What you originally wrote wouldn't work (at least not as intended)=2C > since you're using "artikel" as your loop variable=2C and "article" > inside it. >=20 > -Dave >=20 > --=20 > Dave Aronson=2C T. Rex of Codosaurus=2C LLC... aka > Available Secret-Cleared Ruby/Rails Freelancer > (NoVa/DC/Remote)=3B see http://www.Codosaur.us/. >=20 = --_85f45900-c296-43ec-b9ec-534104137ac5_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hello=2C

Thanks =2C but I only need 1 of the three category but whic= h one is chancing.

Roelof


>=3B Date: Sun=2C 14 Oct 2012 00:43:15 +0900
>=3B From: = rubytalk2dave@davearonson.com
>=3B Subject: Re: multiple array problem=
>=3B To: ruby-talk@ruby-lang.org
>=3B
>=3B On Sat=2C Oct 1= 3=2C 2012 at 7:35 AM=2C Roelof Wobben <=3Brwobben@hotmail.com>=3B wrote= :
>=3B
>=3B >=3B category1.article.each do |artikel|
>=3B= >=3B puts article.name
>=3B >=3B end
>=3B >=3B
>= =3B >=3B category2.article.each do |artikel|
>=3B >=3B puts articl= e.name
>=3B >=3B end
>=3B >=3B
>=3B >=3B category3.art= icle.each do |artikel|
>=3B >=3B puts article.name
>=3B >=3B = end
>=3B >=3B
>=3B >=3B But now I have 3 parts of code which = are almost the same.
>=3B >=3B Is there a way I can make 1 part of c= ode where the category is a variable.
>=3B
>=3B Sure. Make an a= rray out of your 3 arrays: [category1=2C category2=2C
>=3B category3].= Then call .each on THAT. E.g.:
>=3B
>=3B [category1=2C cate= gory2=2C category3].each do |category|
>=3B category.article.each = do |article|
>=3B puts article.name
>=3B end
>=3B = end
>=3B
>=3B Not sure where you're getting category.article f= rom though=3B is
>=3B category an instance of some class like Category= =2C that has an array
>=3B called article? (If so=2C I'd suggest maki= ng the name plural to show
>=3B it's a collection.)
>=3B
>= =3B Which reminds me=2C watch out for mismatches between human languages.>=3B What you originally wrote wouldn't work (at least not as intended)= =2C
>=3B since you're using "artikel" as your loop variable=2C and "ar= ticle"
>=3B inside it.
>=3B
>=3B -Dave
>=3B
>=3B= --
>=3B Dave Aronson=2C T. Rex of Codosaurus=2C LLC... aka
>=3B= Available Secret-Cleared Ruby/Rails Freelancer
>=3B (NoVa/DC/Remote)= =3B see http://www.Codosaur.us/.
>=3B
= --_85f45900-c296-43ec-b9ec-534104137ac5_--