我忘了把這個詞結束,在結束if語句, 並得到了以下錯誤:爲什麼kernel_required.rb在我的堆棧跟蹤中?
/home/***/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': **/home/****/Desktop/ruby/food_finder/lib/restaurant.rb:84: syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)**
from /home/****/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/****/Desktop/ruby/food_finder/lib/guide.rb:1:in `<top (required)>'
from /home/****/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/****/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from init.rb:14:in `<main>'
我的代碼沒有錯誤:
def self.saved_restaurants
# read the restaurant file
restaurants = []
if file_usable?
file = File.new(@@filepath, 'r')
file.each_line do |line|
restaurants << Restaurant.new.import_line(line.chomp)
end
file.close
**end** -- > forgotten end
# return instances of restaurant
return restaurants
end
我的代碼有錯誤:
def self.saved_restaurants
# read the restaurant file
restaurants = []
if file_usable?
file = File.new(@@filepath, 'r')
file.each_line do |line|
restaurants << Restaurant.new.import_line(line.chomp)
end
file.close
-- > forgotten end
# return instances of restaurant
return restaurants
end
我的問題是: 爲什麼我得到的錯誤與我的代碼有關? 像下面這樣:
/home/***/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require':
- 這個錯誤是什麼意思?
當我使用saved_restaurants方法的正確語法時,我不會收到任何錯誤。
謝謝..我現在明白了。 – liron
現在,真正的問題是:爲什麼它是這樣設計的?我沒有答案。 – sawa
它爲什麼要這樣做?任何人? – liron