【发布时间】:2019-04-12 05:16:30
【问题描述】:
我正在使用 ruby:1.9.3
名为 restaurant.txt 的文件,其数据如下:
|"Aloo Fry"| "Carbohydrates bahut hai" | "Nahi Khana"
|"Moong"| "protein bahut hai" | "Khana Hai"
|"Egg"|"Protein hai but non veg"| "Nahi khana hai"
现在我要做的是取出最后一个字符串并删除现有的行。输出文件必须是同一个文件,并且应该如下所示:
Nahi Khana Khana Hai Nahi Khana hai
if ARGV.length != 1
puts "Input only the one file at a time"
exit
end
foodie = ARGV[0]
puts "you have entered file: #{foodie}"
puts "Hold your horses... we are processing"
File.open(foodie, "r+").each do |line|
new_line = line.split("|")[-1]
puts new_line
line.puts new_line
end
我收到错误:
private method `puts' called for "Nahi Khana":String (NoMethodError)
【问题讨论】:
-
我假设您知道对 Ruby v1.9.3 的支持已于四年多前(2015 年 2 月 23 日)结束。
-
是的,不能强制行业更改版本:)
标签: ruby