Mystery with ARGF

Hi!

In last few days I was trying to resolve soem issue with the script from
Ruby/Glade bindings supposed to read *.glade interface file.

Since I was getting very strange error, Masao M. finally rewrote the
script to use ARGV isntead of ARGF.

However, the mystery remains.

If I run the 1 line script below (filename as test.rb).

$ cat test.rb
p ARGF
$ ruby test.rb test.rb
test.rb

instead of “test.rb”, I get “-” (minus sign). Can somebody explain me why
the usage of ARGF does not work ex expected (to give command line
argument back)?

Sincerely,
Gour

···


Gour
gour@mail.inet.hr
Registered Linux User #278493

instead of "test.rb", I get "-" (minus sign).

Well, this is changed in 1.8

pigeon% cat test.rb
p ARGF
pigeon%

pigeon% ruby -v test.rb test.rb test1.rb
ruby 1.8.0 (2003-03-03) [i686-linux]
test.rb
pigeon%

with 1.6, it was initialized to "-" and set to the right value after an
access

pigeon% cat test.rb
p ARGF
ARGF.gets
p ARGF
pigeon%

pigeon% /usr/bin/ruby -v test.rb test.rb test1.rb
ruby 1.6.8 (2002-12-24) [i686-linux]

···

-
test.rb
pigeon%

                                            Can somebody explain me why
the usage of ARGF does not work ex expected (to give command line
argument back)?

ARGF give you the input stream read by the program

ARGF#to_s is the same than ARGF#filename and give the name of the argument
that ruby actually read

Guy Decoux

Well, this is changed in 1.8

pigeon% cat test.rb
p ARGF
pigeon%

pigeon% ruby -v test.rb test.rb test1.rb
ruby 1.8.0 (2003-03-03) [i686-linux]
test.rb
pigeon%

Ahh, now it’s clear.

with 1.6, it was initialized to “-” and set to the right value after an
access

pigeon% cat test.rb
p ARGF
ARGF.gets
p ARGF
pigeon%

The code in the script was: path = ARGF.filename, and therefore the
variable “path” was left with the “-” value.

Thank you very much for your explanation.

In my Pickaxe book, there is nothing regards. Where are you picking such details?

Sincerely,
Gour

···

ts (decoux@moulon.inra.fr) wrote:


Gour
gour@mail.inet.hr
Registered Linux User #278493