Equality Problems

Below is a snip of code that I’m having problems with the test in
the .each method alway will return false and I don’t have a clue why.
Could someone please help?

print “ID=”, @id
print " QTY=", @qty,"\n"
@cart.items.each{|x| print “ProdID=”,x.product.id,"
QTY=",x.quantity," “,(x.quantity==(@qty)),”\n"}

Here is the output of the code above

ID=8 QTY=1
ProdID=8 QTY=1 false
ProdID=5 QTY=1 false
ProdID=7 QTY=1 false
ProdID=8 QTY=2 false
ProdID=8 QTY=3 false
ProdID=7 QTY=2 false

On 2 Dec 2007, at 20:51, [email protected] wrote:

QTY=",x.quantity," “,(x.quantity==(@qty)),”\n"}
@qty is a string, x.quantity is an integer and so the 2 are never equal


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs