What does "ARGF.class" mean?

ruby 1.9.2p180 (2011-02-18) [i386-mingw32]

irb(main):001:0> ARGF.class
=> ARGF.class

What does “ARGF.class” mean? Isn’t ARGF a special IO object, whose class
is “IO”, just like STDIN?

irb(main):002:0> STDIN.class
=> IO

From the source code, I see this:

#define argf_of(obj) (*(struct argf *)DATA_PTR(obj))
#define ARGF argf_of(argf)

… … later on

/*

  • Hack to get rdoc to regard ARGF as a class:
  • rb_cARGF = rb_define_class(“ARGF”, rb_cObject);
    */
    rb_cARGF = rb_class_new(rb_cObject);
    rb_set_class_path(rb_cARGF, rb_cObject, “ARGF.class”);
    rb_define_alloc_func(rb_cARGF, argf_alloc);

That’s not a definitive answer, but it does look like the implementers
are aware that some of ARGF’s edges are hacks.

Right, I understand. I’m just pointing out that ARGF is, in fact, not a
real class, and that Ruby treats ARGF differently from real classes.

David J. wrote in post #985706:

That’s not a definitive answer, but it does look like the implementers
are aware that some of ARGF’s edges are hacks.

I was confused with its class name “ARGF.class”. If ARGF is an instance
of “ARGFClass”, like nil is an instance of “NilClass”, I won’t
misunderstand it. “ARGF.class” doesn’t seem to be a class name.
Thank you.

On Mar 6, 2011, at 4:55 PM, 7stud – wrote:

=> IO

First note that your output is not ARGFCLASS. You really are getting no
output–if what you posted is correct; irb just output what you typed
in.

This is not a correct interpretation of the 1.9.2 output.

ARGF is an instance of a class and the class has the name ‘ARGF.class’.
That is a very unusual class name which makes it a bit difficult to
interpret the IRB output.

IRB prints the result of calling #inspect on the last expression entered
and
for a class that is just the name of the class:

ruby-1.9.2-p0 > ARGF.class
=> ARGF.class
ruby-1.9.2-p0 > a = ARGF.class; 1
=> 1
ruby-1.9.2-p0 > a.inspect
=> “ARGF.class”
ruby-1.9.2-p0 > a.class
=> Class
ruby-1.9.2-p0 > a.name
=> “ARGF.class”
ruby-1.9.2-p0 > ARGF.class.superclass
=> Object
ruby-1.9.2-p0 >

So ARGF is an instance of a class named ‘ARGF.class’ and that class is
just a subclass of Object. ARGF does respond to many of the same
methods
that an instance of IO would respond to but that is just an example
of duck typing rather than inheritance.

ruby-1.9.2-p0 > (ARGF.class.instance_methods(false) &
IO.instance_methods(false))
=> [:fileno, :to_i, :to_io, :each, :each_line, :each_byte, :each_char,
:lines, :bytes, :chars, :read, :readpartial, :readlines, :gets,
:readline, :getc, :getbyte, :readchar, :readbyte, :tell, :seek, :rewind,
:pos, :pos=, :eof, :eof?, :binmode, :binmode?, :close, :closed?,
:lineno, :lineno=, :external_encoding, :internal_encoding,
:set_encoding]
ruby-1.9.2-p0 > ARGF.class.included_modules
=> [Enumerable, Kernel]

Gary W.

Gary W. wrote in post #985859:

This is not a correct interpretation of the 1.9.2 output.

ARGF is an instance of a class and the class has the name ‘ARGF.class’.
That is a very unusual class name which makes it a bit difficult to
interpret the IRB output.

Thanks for the correction…but I’ll stand by my statement:

irb just output what you typed in, which is not at
all helpful.

Having a class actually named “ARGF.class” makes me think that ruby is
an ass.

Joey Z. wrote in post #985705:

ruby 1.9.2p180 (2011-02-18) [i386-mingw32]

irb(main):001:0> ARGF.class
=> ARGF.class

What does “ARGF.class” mean? Isn’t ARGF a special IO object, whose class
is “IO”, just like STDIN?

irb(main):002:0> STDIN.class
=> IO

First note that your output is not ARGFClass. You really are getting no
output–if what you posted is correct because irb just output what you
typed in, which is not at all helpful.

In ruby 1.8.6, I get Object for the output, but as you mentioned I would
have expected ARGF to be some kind of IO object.