From: Filip Moens Date: 2002-03-16T11:57:00+09:00 Subject: Re: Reading a file Into a string You can do something like: mystring = '' File.open("mytext.txt", "r") { |f| mystring = f.read } This way, the file gets closed automatically for you. "Roy J. Milican" wrote in message news:19041685860.20020315180405@milican.com... > Greetings, > > I was wondering if there was a method or maybe a more ruby way of > reading the contents of a file into a string. At the moment the > following was the only way I could think to do it. > > mystring = String::new('') > myfile = File::open("mytext.txt") > myfile.each do |line| > mystring << line > end > > Thanks, > > A Ruby Newbie :) > > -- > Roy Milican > roy@milican.com >