From: MonkeeSage Date: 2007-12-25T07:29:59+09:00 Subject: Re: no method error (because of unknown variable type) On Dec 22, 1:00 pm, "Haris Bogdanovic" wrote: > Problem solved ! > > It's because the file was opened as 'w' and not 'r'. I firstly created file > and put some data into it and then I forgot to close it and reopen it as > 'r'. > It was strange to me that ruby would check for variable types in that way > but obviously I was assuming wrong. > > Thanks. > > "Haris Bogdanovic" wrote in message > > news:fkjhnd$c6f$1@garrison.globalnet.hr... > > > Hi ! > > > Here is a little example: > > > file "Functions.rb": > > #--------------------- > > def func(file) > > if !file.eof then #do something. > > end > > #--------------- > > > file "main.rb": > > > require 'Functions' > > file_1=open('bla.txt','w') > > func(file_1) > > file_1.close > > > I get an error message that eof method is undefined. > > I presume that this is because ruby does not know that the "file" variable > > is going to become a File.object. > > How do I solve this ? > > > Thanks. You can use 'r+' as the open mode if you want reading and writing (rather than closing and reopening the file handle or using IO#reopen). See `ri IO` (near the middle) for a list of available open modes. Regards, Jordan