On Wed, Dec 12, 2012 at 12:51 PM, 林彰史 <[email protected]> wrote:
> Yes I agree that it makes no sense, but I wanted to see how zip method works
> with File IO with a simple experimental code.
> My point is why the second line of input is discarded.

That might be an artifact of unhealthy using of the Enumerator because
you do not really iterate through the whole file but you use it twice
on the same file.  Chances are that the Enumerator fetches the next
item before it is actually uses and #zip just breaks out of the loop
prematurely.  In your example you'd rather want

[1, 2].zip( file.each ) do |n,l| puts "#{n}: #{l}" end

Or you want to reverse order and do

file.zip([1, 2]) do |l, n| puts "#{n}: #{l}" end

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google group. To post to this group, send email to 
[email protected]. To unsubscribe from this group, send email 
to [email protected]. For more options, visit this 
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to