From: badboy Date: 2009-03-09T19:44:34+09:00 Subject: Re: Setting the contents of a file to a variable? Matthias Reitinger schrieb: > Brian Candler wrote: >> BTW, local variables which are first seen within a block are private to >> that block, so if you want do use a local variable do this: >> >> guess = nil >> File.open("guess.txt") do |file| >> guess = file.gets >> end >> ... now 'guess' contains the result of reading the 1st line of file > > Or even this: > > guess = File.open("guess.txt") do |file| > file.gets > end > > Maybe even this (Symbol#to_proc implementation/Ruby 1.9 required): > > guess = File.open("guess.txt", &:gets) > > -Matthias > did you read my post? why should we use a construct with a block if there are several methods to do this directly?