From: Gavin Sinclair Date: 2011-12-09T17:58:42+09:00 Subject: Re: reading from file without end-of-lines > i'm trying to read a few text values from single file: > >  if File.exists?(file) >      File.open(file, 'r+') do |f| >        value1 = f.gets.strip >        value2 = f.gets.strip >        value3 = f.gets.strip >        value4 = f.gets.strip >      end >    end > > each value is stored in separate line and 'strip' above is used only to > get rid of end-of-line characters. is there any easier way to do the same? I tend to strip out all such characters at once, before operating on any line. File.readlines(file).map { |line| line.strip }.each do |line| ... end In your case, I guess that would be lines = File.readlines(file).map { |line| line.strip } value1 = lines.shift value2 = lines.shift # etc. # or v1, v2, v3, v4 = lines.shift(4)