Dirk Einecke wrote: > Hi. > > I've a method to read the content of a file. > > def readFile(path) > value = '' > file = File.open(path, File::RDONLY) > while line = file.gets do > value += line > end > file.close > return value > end > > I think the way line by line is not very efficiently. > Is there a shorter way to get the content of a file? > > greetings > Dirk Einecke Simple way is: content = File.read(filename) But if you should learn about blocks so the code you provided can be replaced with something like the following (because your code doesn't have exception handling to guarantee that file.close is called): File.open(path, File::RDONLY){|file| #use file.gets or whatever in here, preferably using another block }