我忘了把 end 这个词放在 if 语句的末尾,并得到以下错误:
/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 方法使用正确的语法时,我没有收到任何错误。