From: Roelof Wobben Date: 2012-09-26T16:39:34+09:00 Subject: Re: inject problem --_6ba7b6bf-7af6-4b0b-838d-29f041884c19_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Thanks. I know I have a lot to learn. I'm just beginning with ruby and in this moments I miss a IDE where I can d= o everything step by step so I can see what went wrong. Now refractor the if then 's and I hope I can decline it to less then 5 if = then's. But that will be difficult.=20 Roelof > Date: Wed=2C 26 Sep 2012 05:51:29 +0900 > From: lists@ruby-forum.com > Subject: Re: inject problem > To: ruby-talk@ruby-lang.org >=20 > You're iterating over the wrong object. After you've build the hash=2C yo= u=20 > have to iterate over this hash and not the dices arrays again. >=20 > The dices array contains only the numbers. The h hash contains the=20 > numbers and corresponding counts. >=20 > So it's not >=20 > dice.each {|number=2C count| ... >=20 > but >=20 > h.each {|number=2C count| ... >=20 > Since there have been quite some errors now=2C you should be more careful= =20 > with the code you write. And you should get used to testing and=20 > debugging code yourself. The error message is telling you that the ">"=20 > operator has been applied to nil (namely the "count" variable). So if=20 > you didn't already know the problem=2C the first step would be to check=20 > why "count" is nil. You'd do this by outputting "dice"=2C since that's=20 > what you're iterating over. And then you'd probably realized that it's=20 > the completely wrong object. >=20 > --=20 > Posted via http://www.ruby-forum.com/. >=20 = --_6ba7b6bf-7af6-4b0b-838d-29f041884c19_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Thanks.

I know I have a lot to learn.
I'm just beginning with rub= y and in this moments I miss a IDE where I can do everything step by step s= o I can see what went wrong.

Now refractor the if then 's and I hope= I can decline it to less then 5 if then's.
But that will be difficult. =

Roelof


>=3B= Date: Wed=2C 26 Sep 2012 05:51:29 +0900
>=3B From: lists@ruby-forum.c= om
>=3B Subject: Re: inject problem
>=3B To: ruby-talk@ruby-lang.= org
>=3B
>=3B You're iterating over the wrong object. After you'= ve build the hash=2C you
>=3B have to iterate over this hash and not = the dices arrays again.
>=3B
>=3B The dices array contains only = the numbers. The h hash contains the
>=3B numbers and corresponding c= ounts.
>=3B
>=3B So it's not
>=3B
>=3B dice.each {|nu= mber=2C count| ...
>=3B
>=3B but
>=3B
>=3B h.each {|n= umber=2C count| ...
>=3B
>=3B Since there have been quite some e= rrors now=2C you should be more careful
>=3B with the code you write.= And you should get used to testing and
>=3B debugging code yourself.= The error message is telling you that the ">=3B"
>=3B operator has= been applied to nil (namely the "count" variable). So if
>=3B you di= dn't already know the problem=2C the first step would be to check
>= =3B why "count" is nil. You'd do this by outputting "dice"=2C since that's =
>=3B what you're iterating over. And then you'd probably realized tha= t it's
>=3B the completely wrong object.
>=3B
>=3B --
= >=3B Posted via http://www.ruby-forum.com/.
>=3B
=
= --_6ba7b6bf-7af6-4b0b-838d-29f041884c19_--