sublimetext2 - Ruby .gets doesn't work -
i'm trying simple user input in ruby, can't working. i'm using gets
method, program never stops ask me input. i'm using sublime text 2 text editor, , run program in it, (if makes difference).
here's code:
puts "what name?" name = gets puts "hello " + name + ". how you?"
and here's error (and output) given me:
c:/users/sten sootla/desktop/ruby workspace/exercise.rb:3:in `+': can't convert nil string (typeerror) c:/users/sten sootla/desktop/ruby workspace/exercise.rb:3:in `' name? [finished in 0.1s exit code 1]
why doesn't program stop ask me input?
here's how understand it. gets
, puts
instance methods of io
, , default io
s $stdout
, $stdin
.
calls gets/puts effective if translator capable of handling stdout/in e.g. irb
if run ruby file bash works too.
io_test.rb
puts gets
in bash
ruby io_test.rb
then "put" stdout whatever "gets" stdin.
Comments
Post a Comment