Я пытался запустить приведенный ниже код Ruby, но продолжаю получать следующую ошибку:
Failed: ArgumentError: неверное количество аргументов (задано 1, ожидается 0)
stacktrace: ./basic_read_write.rb:3:in write_data_to_file'
/tmp/test.rb:5:in
блок (2 уровня) в
# writes the number of lines then each line as a string.
def write_data_to_file()
a_file=File.new("mydata.txt","w")
a_file.puts('5')
a_file.puts('Fred')
a_file.puts('Sam')
a_file.puts('Jill')
a_file.puts('Jenny')
a_file.puts('Zorro')
a_file.close
end
def read_data_from_file()
a_file=File.new("mydata.txt","r")
count = a_file.gets.to_i
puts count.to_s
for i in 0..count.to_i
puts a_file.gets
end
a_file.close
def main
# open for writing
write_data_to_file()
# open for reading
read_data_from_file()
end
main
end