Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 Ruby 中清理 STDIN?我想确保 STDIN 中没有任何内容。
IO#ready?您可以使用from检查 STDIN 中是否有可用的输入io/wait。用于IO#getc读取字符,将其从缓冲区中删除。
IO#ready?
io/wait
IO#getc
require 'io/wait' def clear_stdin $stdin.getc while $stdin.ready? end