From: Matthias Reitinger Date: 2009-03-09T06:16:59+09:00 Subject: Re: Setting the contents of a file to a variable? 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 -- Posted via http://www.ruby-forum.com/.