当我尝试在命令行上运行我的ruby address_book进行测试时,我收到了这个错误,我不知道代码有什么问题。
错误
address_bloc.rb:1:在
中require_relative': >/Users/paul/address_bloc/controllers/menu_controller.rb:125: syntax error, >unexpected end-of-input, expecting keyword_end (SyntaxError) from address_bloc.rb:1:in
'
-address_bloc.rb
require_relative 'controllers/menu_controller'
menu = MenuController.new
system "clear"
puts "Welcome to AddressBloc!"
menu.main_menu
-controllers / menu_controller.rb
require_relative "../models/address_book"
class MenuController
attr_accessor :address_book
def initialize
@address_book = AddressBook.new
end
def main_menu
puts "Main Menu - #{@address_book.entries.count} entries"
puts "1 - View all entries"
puts "2 - Create an entry"
puts "3 - Search for an entry"
puts "4 - Import entries from a CSV"
puts "5 - Exit"
print "Enter your selection: "
selection = gets.to_i
case selection
when 1
system "clear"
view_all_entries
main_menu
when 2
system "clear"
create_entry
main_menu
when 3
system "clear"
search_entries
main_menu
when 4
system "clear"
read_csv
main_menu
when 5
puts "Good-bye!"
exit(0)
else
system "clear"
puts "Sorry, that is not a valid input"
main_menu
end
end
def view_all_entries
@address_book.entries.each do |entry|
system "clear"
puts entry.to_s
entry_submenu(entry)
end
system "clear"
puts "End of entries"
end
def create_entry
system "clear"
puts "New AddressBloc Entry"
print "Name: "
name = gets.chomp
print "Phone number: "
phone = gets.chomp
print "Email: "
email = gets.chomp
@address_book.add_entry(name, phone, email)
system "clear"
puts "New entry created"
end
def search_entries
end
def read_csv
end
def entry_submenu(entry)
puts "n - next entry"
puts "d - delete_entry"
puts "e - edit this entry"
puts "m - return to main menu"
selection = gets.chomp
case selection
when "n"
when "d"
when "e"
when "m"
system "clear"
main_menu
else
system "clear"
puts "#{selcetion} is not a valid input"
entry_submenu(entry)
end
end
end
谢谢
答案 0 :(得分:0)
您的最终end
即将结束def entry_submenu(entry)
现在您需要最终end
才能关闭class MenuController
像这样:
require_relative "../models/address_book"
class MenuController
attr_accessor :address_book
def initialize
@address_book = AddressBook.new
end
def main_menu
puts "Main Menu - #{@address_book.entries.count} entries"
puts "1 - View all entries"
puts "2 - Create an entry"
puts "3 - Search for an entry"
puts "4 - Import entries from a CSV"
puts "5 - View Entry Number n"
puts "6 - Exit"
print "Enter your selection: "
selection = gets.to_i
case selection
when 1
system "clear"
view_all_entries
main_menu
when 2
system "clear"
create_entry
main_menu
when 3
system "clear"
search_entries
main_menu
when 4
system "clear"
read_csv
main_menu
when 5
system "clear"
display_entry_by_n
main_menu
when 6
puts "Good-bye!"
exit(0)
else
system "clear"
puts "Sorry, that is not a valid input"
main_menu
end
end
def view_all_entries
@address_book.entries.each do |entry|
system "clear"
puts entry.to_s
entry_submenu(entry)
end
system "clear"
puts "End of entries"
end
def create_entry
system "clear"
puts "New AddressBloc Entry"
print "Name: "
name = gets.chomp
print "Phone number: "
phone = gets.chomp
print "Email: "
email = gets.chomp
@address_book.add_entry(name, phone, email)
system "clear"
puts "New entry created"
end
def display_entry_by_n
system "clear"
puts "Enter the entry number"
print "Number:"
selection = get.chomp.to_i
if selection < @address_book.entries.size
puts @address_book.entries[selection]
puts "Press enter to return to main menu"
gets.chomp
system "clear"
else
puts "#{selection} is not a valid input"
display_entry_by_n
end
end
def search_entries
end
def read_csv
end
def entry_submenu(entry)
puts "n - next entry"
puts "d - delete_entry"
puts "e - edit this entry"
puts "m - return to main menu"
selection = gets.chomp
case selection
when "n"
when "d"
when "e"
when "m"
system "clear"
main_menu
else
system "clear"
puts "#{selcetion} is not a valid input"
entry_submenu(entry)
end
end
end