From: Tammo Tjarks Date: 2007-08-26T00:20:05+09:00 Subject: Re: reusing the result of previous iteration step for comparison Thank you very match, that helps. Regards, Tammo Logan Capaldo wrote: > On 8/25/07, Tammo Tjarks wrote: >> 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| ????????} >> } >> > a.select { |elemkey, elemattr| elemattr.all? { |v| v[0] == v[1] } } > >> >> Regards, >> Tammo >> >> >>