From: "Aaron D. Gifford" Date: 2011-04-07T03:49:42+09:00 Subject: Re: String#each_*slice* methods (like Enumerable#each_slice) Quintus replied: > Use Enumarators: > ================================ > irb(main):001:0> str = "ÄÄÄÖÖÖÜÜÜ" > => "ÄÄÄÖÖÖÜÜÜ" > irb(main):002:0> str.chars.each_slice(3){|x| p x} > ["Ä", "Ä", "Ä"] > ["Ö", "Ö", "Ö"] > ["Ü", "Ü", "Ü"] > => nil > irb(main):003:0> str.bytes.each_slice(3){|x| p x} > [195, 132, 195] > [132, 195, 132] > [195, 150, 195] > [150, 195, 150] > [195, 156, 195] > [156, 195, 156] > => nil > irb(main):004:0> > ================================ > > Vale, > Marvin Yes, I agree, that can work. As I said in my original post: >> One alternative each_bslice implementation I tried used >> str.bytes.to_a.map(&:chr).each_slice(x){|c| p c.join} but it was a bit >> slower in benchmarks versus the str.scan method. That implementation did use enumerators. But it was slower than str.scan. Hence my asking if there was a better (faster/more efficient) way. I didn't try benchmarking str.chars.each_slice vs str.scan. I'll have to check that out. Thanks for pointing that out to me! Aaron out.