If we capture the objects and look at them using just pure Ruby we can see a few things:
1.9.3 (Object#main):0 > ARGFClass = ARGF.class
=> ARGF.class
1.9.3 (Object#main):0 > ARGFClass.name
=> "ARGF.class"
1.9.3 (Object#main):0 > ARGFClass.class
=> Class
1.9.3 (Object#main):0 > ARGFClass.superclass
=> Object
1.9.3 (Object#main):0 > ARGFClass.ancestors
=> [ARGF.class,
Enumerable,
Object,
JSON::Ext::Generator::GeneratorMethods::Object,
PP::ObjectMixin,
Kernel,
BasicObject]
For some reason, the developers have explicitly set the class.name value to return ARGF.class
, which is generally uncommon but is used internally in Ruby for constants that should never be accessed directly.
We can instantiate objects with the ARGFClass exactly the same as any other class. That means it is a real Ruby class:
1.9.3 (Object#main):0 > argfinstance = ARGFClass.new
=> ARGF
1.9.3 (Object#main):0 > argfinstance.inspect
=> "ARGF"
It's not just returning the singleton when you call #new either:
1.9.3 (Object#main):0 > argfinstance == ARGF
=> false
1.9.3 (Object#main):0 > argfinstance.object_id
=> 70346556507420
1.9.3 (Object#main):0 > ARGF.object_id
=> 70346552343460
The Ruby developers have intentionally named the ARGF.class
in such a way that it can't be referenced directly by name, but it is a real class and ARGF
is a real object.
It has a lot of the same methods as an IO object, and in fact is defined in the io.c
source file. It also has the Enumerable module mixed in so it supports all the each/inject/map functionality.
edit: The documentation lists ARGF
as a class. However, its actually a constant referencing a singleton instance of the oddly named ARGF.class
class.
References