Ruby编写一个程序,从键盘输入字符串写入指定文件
========================================
方法1:
#!/usr/bin/env ruby -w fh = File.open("test.txt", "w") while (gets.chomp) break if ~/^quit/ fh.puts $_ end fh.close
方法2:
File.open("xxx.txt", 'w') do |f| #Ctrl+C 结束执行 while gets f.puts $_ end end