1

我正在运行一个包含以下内容的 Ruby 脚本:

def addCourses 
crns = []

loop do                                   Line 168
    system("clear")
    puts "Your CRNs:".color(:red)
    crns.each do |crn|
        puts "  -> #{crn[:title]} (CRN: #{crn[:crn]})".color(:magenta)
end

    #Prompt for CRN
    alt = (crns.length > 0)  ? " (or just type 'start') " : " "
    input = ask("\nEnter a CRN to add it#{alt}".color(:green) + ":: ") { |q| q.echo = true }        LINE 177     

    #Validate CRN to be 5 Digits 
    if (input =~ /^\d{5}$/) then

        #Display CRN Info
        c = getCourse(input.to_s)
        puts "\nCourse: #{c[:title]} - #{c[:crn]}".color(:red)
        puts "--> Time: #{c[:begin]}-#{c[:end]} on #{c[:days]}".color(:cyan)
        puts "--> Teacher: #{c[:instructor]}".color(:cyan)
        puts "--> Type: #{c[:type]} || Status: #{c[:status]}".color(:cyan)
        puts "--> Availability: #{c[:seats]} / #{c[:capacity]}\n".color(:cyan)

        #Add Class Prompt
        add = ask("Add This Class? (yes/no)".color(:yellow) + ":: ") { |q| q.echo = true }
        crns.push(c) if (add =~ /yes/)

    elsif (input == "start") then
        checkCourses(crns)
    end 
end
end

但我收到一个错误:

您的 CRN:

Enter a CRN to add it :: /Library/Ruby/Gems/1.8/gems/highline-1.6.18/lib/highline.rb:844:in `get_line': The input stream is exhausted. (EOFError)
from /Library/Ruby/Gems/1.8/gems/highline-1.6.18/lib/highline.rb:867:in `get_response'
from /Library/Ruby/Gems/1.8/gems/highline-1.6.18/lib/highline.rb:259:in `ask'
from Untitled.rb:177:in `addCourses'
from Untitled.rb:168:in `loop'
from Untitled.rb:168:in `addCourses'
from Untitled.rb:210:in `main'
from Untitled.rb:217

我不完全确定是什么导致了错误,因为我在其他地方有类似的代码,它们具有相同的基本目的。此错误的原因可能是什么?我在相应代码右侧的顶部块中包含了适当的代码行号。

4

0 回答 0