Running this:
# p005methods.rb
# gets and chomp
puts "In which city do you stay?"
STDOUT.flush
city = gets.chomp
puts "The city is " + city
I get this:
ruby p004stringusage.rb
In which city do you stay?
p004stringusage.rb:5:in `gets': Bad file descriptor (Errno::EBADF)
from p004stringusage.rb:5
Exit code: 1
What is whrong?
Regards,
Heitor Faria
www.bacula.com.br
11175
(-- --)
June 16, 2009, 4:09pm
3
Agree with Bill..
I tested this in IRB and it works fine.. What OS are you using?
Im using Ubuntu 8.0.
On irb, the "gets" works - but not on that script Im running using the
SciTE editor.
What do you mean "running using the SciTE editor"?
What happens when you run the script from the command line?
Bill
On command line seems ok:
# p005methods.rb
# gets and chomp
puts "In which city do you stay?"
In which city do you stay?
=> nil
STDOUT.flush
=> #<IO:0xb7c72f74>
city = gets.chomp
salvador
=> "puts \"The city is \" + citysalvador"
That's either irb or script/console. I meant run the script from the
command line.
ruby p005methods.rb
Gee... Im really a newbie... =P
# ruby p004stringusage.rb
In which city do you stay?
salvador
The city is salvador
We all were. Welcome aboard!
Best regards,
Bill