From: "Albert L. Wagner" Date: 2002-01-12T00:57:11+09:00 Subject: Re: "each" in iterator: confusion Ah, hah! Thank you both. It seems so obvious when you point it out, but if I didn't risk feeling foolish I never would have seen it. Thanks again. "Albert L. Wagner" wrote: > > I do not understand why this code runs forever. Is it because > the yield is taken to be a second yield in the super class > "each"? Is there a way to do such nested iterators? > > class MyHash < Hash > def each(&block) > super.each do | k, v | > v2 = v * 2 > yield( k, v2) > end > end > end > > h = MyHash.new > h['a'] = 1 > h['b'] = 2 > h['c'] = 3 > h.each do | k, v | puts "#{k}==>#{v}" end > > -- > "It requires wisdom to understand wisdom: > the music is nothing if the audience is deaf." > - Walter Lippman -- "It requires wisdom to understand wisdom: the music is nothing if the audience is deaf." - Walter Lippman