I’m not sure if Ruby’s File.open method isn’t properly documented, or I’m missing something.
The File class inherits from IO, which is where the open method seems to be defined. As far as I can tell from the documentation, File doesn’t seem to override IO‘s implementation of the open method.
The documentation for File documents the IO.open class method as taking a numeric file descriptor argument, presumably an object returned by IO.sysopen. However, the apparently undocumented File.open method will just take a filename.
For example, this fails and quite rightly so according to the documentation:
IO.open('data/actors.list') do |io|
#...
end
On the other hand, this works:
File.open('data/actors.list') do |io|
#...
end
The trouble is, File.open appears to override IO.open and has a different interface, but it’s not documented — or at least doesn’t appear so.
Am I missing something? What’s going on here?
The ruby documentation is wrong, File.open overrides IO.open in order to accept a filename:
http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_file.html#File.new
and
http://www.ruby-forum.com/topic/1731075#999707