From: Kirk Haines Date: 2006-06-05T08:09:22+09:00 Subject: Re: Class args On Sunday 04 June 2006 4:50 pm, Stuart Brand wrote: > class ReadFile > def ReadFile.openAndRead(arg) > f = File.open(arg, "r") > yield f > f.close() > end > end > when it run I get a initialize': No such file or directory - > thefileiwanttoopen It must relate to how you are using it, as there's no error with the code as written. On the face, that just says to me that the arg that you are passing points somewhere where there is nothing to open. ----- class ReadFile def ReadFile.openAndRead(arg) f = File.open(arg, "r") yield f f.close() end end ReadFile.openAndRead('/tmp/readfile.rb') {|f| puts f.read} ----- ruby /tmp/readfile.rb It should print the file back out to you. A couple suggestions, though. First, most of the time you will probably want to use the block form of File.open. Also, read only mode is assumed if no mode is given, so you can simpify your code as: file.open(arg) {|f| yield f} Beyond that, you're going to have to provide more context for us to help much. Kirk Haines