From: "Simon Kröger" Date: 2005-09-03T07:49:18+09:00 Subject: Re: Idiomatic conversion of yielding block to array Levin Alexander wrote: > On 9/3/05, Simon Kr�ger wrote: > > >>food for thoughts... > > > require 'generator' > > s1 = %w{this is the first line}.join("\n") > s2 = %w{this is the second line}.join("\n") > > compare = SyncEnumerator.new(s1.to_enum(:each_line), s2.to_enum(:each_line)) > compare.each { |a,b| > # ... > } > > > -Levin > > Yes, perfekt, that's what i was looking for (and implemented :) ) the trivial solution is of course: ---------------------------------------------------------- s1 = ['this', 'is', 'a', 'test'].join("\n") s2 = ['this', 'is', 'the', 'test'].join("\n") (0...s1.size).inject(1) do |l, i| puts "difference on line: #{l}" or break if s1[i] != s2[i] l = (s1[i] == 10) ? l+1 : l end ---------------------------------------------------------- buts that no fun.. Simon