[#113] Re: ruby 1.1d0 released — matz@... (Yukihiro Matsumoto)
Hi.
7 messages
1998/12/16
[#127] very very NEWbie — "Bryce" <crowdog@...>
Ok, I'm having trouble with an extremely simple class.
5 messages
1998/12/20
[#138] Thread Problems — Reimer Behrends <behrends@...>
I have been looking at the thread implementation of Ruby for the past
21 messages
1998/12/23
[#164] Re: Thread Problems
— matz@... (Yukihiro Matsumoto)
1999/01/05
Hi.
[#167] Makefiles and -lcurses
— Klaus.Schilling@...
1999/01/05
Julian Fondren writes:
[#168] Re: Makefiles and -lcurses
— Julian Fondren <julian@...>
1999/01/05
OpenBSD has ncurses and it's own ocurses, and I prefer the latter.
[#169] hah, check these errors
— Julian Fondren <julian@...>
1999/01/05
/usr/lib/libm.so.0.1: Undefined symbol `__GLOBAL_OFFSET_TABLE_' referenced
[#170] Re: hah, check these errors
— matz@... (Yukihiro Matsumoto)
1999/01/05
Hi.
[#171] another question about Makefiles
— Julian Fondren <julian@...>
1999/01/05
Hello,
[#172] Re: another question about Makefiles
— matz@... (Yukihiro Matsumoto)
1999/01/05
Hi.
[#174] some more information
— Julian Fondren <julian@...>
1999/01/06
greetings,
[#175] Re: some more information
— matz@... (Yukihiro Matsumoto)
1999/01/06
Hi.
[#179] Re: some more information
— matz@... (Yukihiro Matsumoto)
1999/01/07
In message "[ruby-talk:00175] Re: some more information"
[#140] ruby 1.3 released — matz@... (Yukihiro Matsumoto)
Hi, all.
10 messages
1998/12/24
[#141] Re: ruby 1.3 released
— Clemens Hintze <c.hintze@...>
1998/12/24
On 24 Dec, Yukihiro Matsumoto wrote:
[#143] Re: ruby 1.3 released
— matz@... (Yukihiro Matsumoto)
1998/12/25
Hi.
[#148] inability to load extension modules in 1.2, core dump
— Julian Fondren <julian@...>
1998/12/27
Ok.. 1.1d9 worked with no problems, and no significant or relevent changes
[#149] Re: inability to load extension modules in 1.2, c ore dump
— Clemens Hintze <c.hintze@...>
1998/12/27
On 27 Dec, Julian Fondren wrote:
[ruby-talk:00123] Re: finished simple script
From:
gotoken@... (GOTO Kentaro)
Date:
1998-12-18 21:44:51 UTC
List:
ruby-talk #123
In message "[ruby-talk:00122] Re: finished simple script"
on 98/12/18, Julian Fondren <julian@imaji.net> writes:
>> Humm... I can't find such situation for the above script :-(
>> Would you tell me what input shows that ``.'' is translated to 32,
>> or explain me the reason why you think so?
>
>I don't know. Yesterday 1 * . gave 32.. but then yesterday this script
>also allowed me to press enter 2000 times, 1, enter 2000 times, 2 and
>get the answer of 2. Strange.
To consider the problem, I tried as follows.
I put ``p [ans1, ans2]'' at the end of your script, say `get2nums.rb',
then the script was as follows:
(`%' for the shell prompt)
% cat get2nums.rb
#!/usr/bin/env/ruby
print "Input two numbers to multiply together: \n"
ans1, ans2 = STDIN.gets.chomp.scan(/\d+/).collect { |x| x.to_i }
while !ans1
if !ans1
ans1, ans2 = STDIN.gets.to_i, STDIN.gets.to_i
end
end
while !ans2
if !ans2
ans2 = STDIN.gets.to_i
end
end
p [ans1,ans2]
%
With the above, I got:
% ruby -v
ruby 1.1c9(98/11/26) [i386-freebsd2.1.0]
% echo "1 * ." | ruby get2nums.rb
Input two numbers to multiply together:
[1, 0]
% ruby -e 'print ("\n"*2000,1,"\n"*2000,2)' | ruby get2nums.rb
Input two numbers to multiply together:
[0, 0]
%
... Maybe, I can't get as same as what you get :-(
Would you try the aboves and show me the results?
However, I see because of what I got. The pieces of the fact are
"1 * .\n".chomp #=> "1 * ."
"1 * .".scan(/\d+/) #=> ["1"]
["1"].collect{|x| x.to_i} #=> [1]
ans1, ans2 = [1] #=> ans1 == 1, ans2 == nil
nil.to_i #=> 0
"\n".to_i #=> 0
etc...
By the way, `p' is a built-in function which is mimicked by
def p(*args)
STDOUT.print *args.collect{|elm| elm.inspect + "\n"}
STDOUT.flush
nil
end
This function is often useful for quick debugging.
I hope that you know `p' already.
-- gotoken