FileObject is a class whose instances contain an internal object created from a file. The internal object is kept up to date by recreating it if the file changes. FileObjects act as a delegate for the internal object and are almost completely transparent. Exceptions that might be raised when the file is read are not rescued, that is left to a higher level.
text = FileObject.new("text.txt") { |file| file.read }
print text
# text.txt gets changed
print text # new content!
-Even though this code is more than a year old, I still want to fix one little detail.-
Holy cows! One of my first Ruby libraries and I haven’t released it yet? I’m such a procrastinator.