【发布时间】:2015-01-28 03:55:27
【问题描述】:
我用 ruby 编写了一个代码,它基本上需要 3 个命令行参数,然后是键盘的用户输入。问题是当我在没有命令行的情况下执行代码时,它能够读取用户输入,但使用命令行却抛出错误“gets”:没有这样的文件或目录 - 3024(Errno::ENOENT) 不明白为什么
class Matching
attr_reader :sys_count
def initialize()
@sys_count = gets
throw "Bad count" unless @sys_count.to_i > 0
end
def get_match
count = @sys_count
return nil unless count
ret = count
count.to_i.times do
ret += gets
end
((count.to_i * (count.to_i - 1))/2).times do
while true do
line = gets
ret += line
break if line == "\n"
end
end
ret
end
def packet
str = get_match
return nil unless str
"matched 0\njava\n" + str
end
end
CONN=ARGV[0]
CONFIG=ARGV[1]
OUT_BASE=ARGV[2]
obj=Matching.new()
out=obj.packet
print out
是否有任何解决方法可以使它工作 ~
【问题讨论】:
标签: ruby