Scnaf Patch?

T

Takao Ueda

It seems pos is undefined for STDIN.
In order to use scanf for console input I had to change the line
start_position = pos
in class IO, def scanf(str, &b) in lib/ruby/1.8/scanf.rb into
if self == STDIN
start_position = 0
else
start_position = pos
end

Any ideas?
 
D

David A. Black

Hi --

It seems pos is undefined for STDIN.
In order to use scanf for console input I had to change the line
start_position = pos
in class IO, def scanf(str, &b) in lib/ruby/1.8/scanf.rb into
if self == STDIN
start_position = 0
else
start_position = pos
end

Any ideas?

I believe this broke some time after 1.6.8, when pos was removed from
STDIN. It was subsequently fixed, though:

wobblini:~$ ruby -vrscanf -e 'p STDIN.scanf("%d%s")'
ruby 1.8.2 (2004-07-29) [i686-linux]
123 abc
^D
[123, "abc"]

(The line you quoted is now:

start_position = pos rescue 0

:)


David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top