From: Bryan JJ Buckley Date: 2008-05-30T02:00:26+09:00 Subject: Re: File.open auto-close It's even easier :) Try the_text = File.read("somefile.txt") Sammy Larbi wrote: > I know opening a file and passing a block will execute the block in context > of the file and then close the file. > > Example: > > File.open("somefile.txt") {|f| the_text = f.read } > > After running, somefile.txt will be closed. > > I'm wondering if it's ok to read a file like this: > > the_text = File.open("somefile.txt").read > > Will that close automatically? If not, how would I go about closing it? > > Thanks, > Sam > >