LoginSignup
0
0

More than 5 years have passed since last update.

エラーがでて実行できません...わかる方教えてください!あと、コード長くて申し訳ございません!

Posted at

require "date"
class BookInfo
def initialize(title,author,page,publish_date)
@title = title
@author = author
@page = page
@publish_date = publish_date
end
attr_accessor :title, :author, :page, :publish_date
def to_s
"#{title},#{author},#{page},#{publish_date}"
end
def toFormattedString(sep = "\n")
"書籍名:#{@title}#{sep}著者名:#{@author}#{sep}ページ数:#{@page}ページ#{sep}
発刊日:#{@publish_date}#{sep}"
end
end

class BookInfoManager
def initialize
@book_infos = {}
end
def setUp
@book_infos["Yamada2005"] = BookInfo.new(
"モバイルボヘミアン",
"加味真",
618,
Date.new(2018,6,18)
)
@book_infos["ooba2006"] = BookInfo.new(
"読書",
"加味真",
619,
Date.new(2017,6,18)
)
end
def addBookInfo
book_info = BookInfo.new("","",0,Date.new)
print "\n"
print "キー:"
key = gets.chomp
print "書籍名:"
book_info.title = gets.chomp
print "著者名:"
book_info.author = gets.chomp
print "ページ数:"
book_info.page = gets.chomp.to_i
print "発刊年:"
year = gets.chomp.to_i
print "発刊月:"
month = gets.chomp.to_i
print "発刊日:"
day = gets.chomp.to_i
boook_info.publish_date = Date.new(yaer,month,day)
end
def listAllBookInfos
puts "\n---------------------"
@book_infos.each {
|key,value|
print info.toFormattedString
puts "\n-------------------------"
}
end
def run
while true do
print "
1.蔵書データの登録
2.蔵書データの表示
9.終了
 番号を選んでください(1,2,9):"
 
 num = gets.chomp
 case num
 when "1"
  addBookInfo
 when "2"
  listAllBookInfos
 when "9"
 

 end
end
end
end
book_info_manager = BookInfoManager.new
book_info_manager.setUp
book_info_manager.run

0
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0