From: Justin Collins Date: 2009-02-27T11:38:21+09:00 Subject: Re: Setting the contents of a file to a variable? Stefan Codrescu wrote: > Ok so... > Ok... so I have file1 and it contains a number > and I want file2 to tell me what that number is > file2 would be something like > > class Tell > def get_num(file = "file1.txt") > num = contents of file1 > $num = num > end > def tell_num > puts "The number in file1 is #{$num}." > end > end > > What do I put instead of "contents of file1" > Or some completely new code that does the same thing. > > File.read file You probably also want $num to be @num instead (that is, an instance variable rather than a global variable). -Justin