可能重复:
Why isn't 'gets' working in my Ruby script when I run from TextMate?
我正在尝试运行一个文件(p015elsifex.rb)
在Mac (雪豹)上使用Textmate。
当我试图运行代码时,我得到一个错误: NoMethodError:私有方法'chomp‘在p015elsifex.rb第6行的顶层调用nil:NilClass
因此,它到了第6行,而不是要求键盘输入,它只是退出。
以下是代码:
#elsif example
#Original example
puts "Hello, what's your name?"
STDOUT.flush
name = gets.chomp
puts 'Hello, ' + name + '.'
if name == 'Satish'
puts 'What a nice name!!'
else
if name == 'Sunil'
puts 'Another nice name!'
end
end
# Modified example with elsif
puts "Hello, what's your name?"
STDOUT.flush
name = gets.chomp
puts 'Hello, ' + name + '.'
if name == 'Satish'
puts 'What a nice name!!'
elsif name == 'Sunil'
puts 'Another nice name'
end
# Further modified
puts "Hello, what's your name?"
STDOUT.flush
name = gets.chomp
puts 'Hello, ' + name + '.'我怎么才能解决这个问题?
发布于 2011-07-04 23:49:02
在Terminal窗口中而不是在TextMate中运行程序。作为一个背景任务,它显然没有标准的输入。
我相信您最终可以将TextMate配置为您想做的事情,但现在只需保持简单即可。
https://stackoverflow.com/questions/6576692
复制相似问题