因此,我有一个下面的方法可以使用,而无需使用stdin或stdout。
def main(lines)
lines.each_index do |i|
word = lines[i]
if word.length > 1 && word.length <=11
puts "I use #{word}"
end
end
end
main(["Google", "yahoo", "stackoverflow", "reddit"])
但是我试图了解stdin和stdout如何与上述功能一起使用。
因此,当标准输入为“ Google”时,标准输出为“我使用Google”
为了使它工作,我不得不用上述数组替换main(readlines)。
main(readlines) ===> main(["Google", "yahoo", "stackoverflow", "reddit"])
我不知道如何执行此操作的命令行。
对于stdouts,在推杆之前会出现吗?
stdout.puts "I use #{word}"
以下列方式之一使用:
$stdout.puts "I use #{word}"
或
STDOUT.puts "I use #{word}"