What is the syntax for passing a File to a Class?

Hi,

I have a log file that I’ve created using the simple command:

logFile = File.new("../LOGS/IF4IT.log", "w")

I can easily write to it at a global level using syntax like:

logFile.puts 'Write this string to logFile.'

I’d like to pass the log file into a Class I’ve defined so I can print
to the logFile from inside Class methods. I try to pass in the log file
like I would any other variable but I get error messages. Is there a
specific syntax that I should be using?

class MyClass
def initialize stringOne, stringTwo, logFile

end
end

The above class yields errors when I try to invoke it using:

newMyClass = MyClass.new stringA, stringB, logFile

I’ve tried to find documentation that talks about passing Files as
arguments to methods and to classes but can’t seem to find anything
obvious. Any thoughts?

Thanks for your help, in advance!

Frank

Frank G. wrote:

I’d like to pass the log file into a Class I’ve defined so I can print
to the logFile from inside Class methods. I try to pass in the log file
like I would any other variable but I get error messages. Is there a
specific syntax that I should be using?

class MyClass
def initialize stringOne, stringTwo, logFile

end
end

The above class yields errors when I try to invoke it using:

newMyClass = MyClass.new stringA, stringB, logFile

I’ve tried to find documentation that talks about passing Files as
arguments to methods and to classes but can’t seem to find anything
obvious. Any thoughts?

Thanks for your help, in advance!

Frank

logFile is a just a regular variable like everything else, there’s no
special syntax for using it just because it refers to a File object.
Your assignment should work; whats the actual error message and the
actual code that causes it?