So what I am trying to do is pass a file name into a method and and check if the file is closed. What I am struggling to do is getting a file object from the file name without actually opening the file.
def file_is_closed(file_name) file = # The method I am looking for file.closed? end I have to fill in the commented part. I tried using the load_file method from the YAML module but I think that gives the content of the file instead of the actual file.
I couldn't find a method in the File module to call. Is there a method maybe that I don't know?
lsofcommand available in your OS. My question is, why don't you know if the file is open or closed and/or, why do you need to know? What are you trying to accomplish? Perhaps if we knew that we could give a better way of doing what you want to do. In general it's bad practice to have files open longer than they need to be and you should use the block form when opening file to automatically close them.File.openwith a block and the file is closed automatically.