In Ruby 1.8.7, the documentation does not list ARGF under classes and modules, and ARGF isn’t a class or a module:
ARGF.class # => Object
In Ruby 1.9.3, the documentation has ARGF under classes and modules, but I see this:
ARGF.class # => ARGF.class
ARGF.superclass # => NoMethodError: undefined method `superclass' for ARGF:ARGF.class
ARGF.class.superclass # => Object
- Why does Ruby 1.9 documentation place
ARGFas a class when the actual class is something else? Or are they the same thing? - Is
ARGF.classa metaclass, a virtual class, singleton class, or something else?
ARGFis implemented in C and you can do weird things in it. TheARGFclass is defined there first. It is not set to any constant in Ruby, but its name is set to “ARGF.class”.Then
ARGFconstant is set to an instance of that class.Here is a Ruby code that is doing roughly the same thing.
It does not look reasonable in Ruby, but in C it is fine. Although, I think the class could be set to
ARGFClasslikeNilClass,TrueClass,FalseClass, so that it is not confusing.I don’t know the history of the change. I think Ruby core folks wanted to get
ARGFinto the docs and this was the simplest way. (RDoc can’t show documentation for singleton objects.)