From: Tammo Tjarks Date: 2007-08-26T00:10:05+09:00 Subject: reusing the result of previous iteration step for comparison I have the general the following kind of problem. I want to check somethin which has to hold for the whole collection. I need it for the selection comand. Simplified it is something like that a = { "tst1" => [[1,0],[0,1]], "tst2" => [[0,0],[1,1]], "tst3" => [[0,0],[1,1]]} a.select {|elemkey,elemattr| equal = true elemattr.each {|v| equal = equal && (v[0]==v[1])} equal == true } That works so far, but I think it is not a nice solution. Because I use the fact, that I use the variable equal which is defined outside the each-block. I am even unsure if that will work anymore with the next ruby-versions (1.9). Is there a solution only working with variables inside the each block? I would prefer a solution with: a = { "tst1" => [[1,0],[0,1]], "tst2" => [[0,0],[1,1]], "tst3" => [[0,0],[1,1]]} a.select {|elemkey,elemattr| equal = elemattr.each {|v| ????????} } Regards, Tammo