【问题标题】:How to write a script that can deal with input in the format of ARGF as well as file in Ruby如何编写一个脚本来处理 ARGF 格式的输入以及 Ruby 中的文件
【发布时间】:2014-09-07 13:59:45
【问题描述】:

有没有简洁的方法呢?

案例一

File.open(infile, 'r').readlines.each do |line|
  process
end

案例2

ARGF.readlines.each do |line|
  process
end

【问题讨论】:

    标签: ruby ruby-2.1


    【解决方案1】:

    这就是你要找的吗?

    method = something_to_help_me_decide ? File.open(infile, 'r') : ARGF
    method.readlines.each do |line|
      process
    end
    

    不太清楚你在这里做什么。

    【讨论】:

    • 谢谢。这正是我想要得到的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-10
    • 2013-01-22
    • 2019-09-27
    • 2014-11-22
    • 1970-01-01
    • 2014-02-23
    相关资源
    最近更新 更多