質問編集履歴

1

参照元のコードを記述しました。

2015/11/19 10:32

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -51,3 +51,91 @@
51
51
 
52
52
 
53
53
  -------------------------------------
54
+
55
+
56
+
57
+
58
+
59
+ 11/19 追記
60
+
61
+
62
+
63
+ # -*- coding: utf-8 -*-
64
+
65
+ require 'date'
66
+
67
+
68
+
69
+
70
+
71
+ class BookInfo
72
+
73
+
74
+
75
+ def initialize( title, author, page, publish_date )
76
+
77
+ @title = title
78
+
79
+ @author = author
80
+
81
+ @page = page
82
+
83
+ @publish_date = publish_date
84
+
85
+ end
86
+
87
+
88
+
89
+ attr_accessor :title, :author, :page, :publish_date
90
+
91
+
92
+
93
+
94
+
95
+ def to_s
96
+
97
+ "#{@title}, #{@author}, #{@page}, #{@publish_date}"
98
+
99
+ end
100
+
101
+
102
+
103
+
104
+
105
+ def toFormattedString( sep = "\n" )
106
+
107
+ "書籍名: #{@title}#{sep}著者名: #{@author}#{sep}ページ数: #{@page}ページ#{sep}発刊日: #{@publish_date}#{sep}"
108
+
109
+ end
110
+
111
+ end
112
+
113
+
114
+
115
+ book_info = BookInfo.new(
116
+
117
+ "ドラゴンポール",
118
+
119
+ "鳥山 あきお",
120
+
121
+ 248,
122
+
123
+ Date.new( 2010, 10, 25 ) )
124
+
125
+
126
+
127
+
128
+
129
+ puts book_info.to_s
130
+
131
+
132
+
133
+ puts book_info.toFormattedString
134
+
135
+ puts book_info.toFormattedString( "/" )
136
+
137
+
138
+
139
+
140
+
141
+ 以上です。