質問編集履歴
3
編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -168,69 +168,69 @@
|
|
168
168
|
|
169
169
|
```
|
170
170
|
|
171
|
-
require "date"
|
172
|
-
|
173
|
-
require 'optparse'
|
174
|
-
|
175
|
-
day = Date.today
|
176
|
-
|
177
|
-
options = ARGV.getopts("y:", "m:")
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
if options["y"]
|
182
|
-
|
183
|
-
puts year = options["y"].to_i
|
184
|
-
|
185
|
-
else
|
186
|
-
|
187
|
-
puts year = day.year
|
188
|
-
|
189
|
-
end
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
if options["m"]
|
194
|
-
|
195
|
-
puts year = options["m"].to_i
|
196
|
-
|
197
|
-
else
|
198
|
-
|
199
|
-
puts year = day.mon
|
200
|
-
|
201
|
-
end
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
head = Date.today.strftime("%B, %Y")
|
206
|
-
|
207
|
-
year = Date.today.year
|
208
|
-
|
209
|
-
mon = Date.today.mon
|
210
|
-
|
211
|
-
firstday = Date.new(year,mon, 1).wday
|
212
|
-
|
213
|
-
lastday = Date.new(year,mon, -1).day
|
214
|
-
|
215
|
-
week = %w(Su Mo Tu We Th Fr Sa)
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
puts head.center(20)
|
220
|
-
|
221
|
-
puts week.join(" ")
|
222
|
-
|
223
|
-
print " " * firstday
|
171
|
+
require "date"
|
172
|
+
|
173
|
+
require 'optparse'
|
174
|
+
|
175
|
+
day = Date.today
|
176
|
+
|
177
|
+
options = ARGV.getopts("y:", "m:")
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
if options["y"]
|
182
|
+
|
183
|
+
puts year = options["y"].to_i
|
184
|
+
|
185
|
+
else
|
186
|
+
|
187
|
+
puts year = day.year
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
if options["m"]
|
194
|
+
|
195
|
+
puts year = options["m"].to_i
|
196
|
+
|
197
|
+
else
|
198
|
+
|
199
|
+
puts year = day.mon
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
head = Date.today.strftime("%B, %Y")
|
206
|
+
|
207
|
+
year = Date.today.year
|
208
|
+
|
209
|
+
mon = Date.today.mon
|
210
|
+
|
211
|
+
firstday = Date.new(year,mon, 1).wday
|
212
|
+
|
213
|
+
lastday = Date.new(year,mon, -1).day
|
214
|
+
|
215
|
+
week = %w(Su Mo Tu We Th Fr Sa)
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
puts head.center(20)
|
220
|
+
|
221
|
+
puts week.join(" ")
|
222
|
+
|
223
|
+
print " " * firstday
|
224
224
|
|
225
225
|
|
226
226
|
|
227
227
|
wday = firstday
|
228
228
|
|
229
|
-
(1..lastday).each do |date|
|
229
|
+
(1..lastday).each do |date|
|
230
|
-
|
230
|
+
|
231
|
-
print date.to_s.rjust(2) + " "
|
231
|
+
print date.to_s.rjust(2) + " "
|
232
|
-
|
232
|
+
|
233
|
-
if Date.new(year,mon,date).wday == 6
|
233
|
+
if Date.new(year,mon,date).wday == 6
|
234
234
|
|
235
235
|
puts "\n"
|
236
236
|
|
2
該当コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -161,3 +161,111 @@
|
|
161
161
|
|
162
162
|
|
163
163
|
Mac、VScode(テキストエディタ)
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
### 該当のソースコード
|
168
|
+
|
169
|
+
```
|
170
|
+
|
171
|
+
require "date" #dateクラスのデータを受け取る
|
172
|
+
|
173
|
+
require 'optparse' #optparseクラスのデータを受け取る
|
174
|
+
|
175
|
+
day = Date.today #今日の情報
|
176
|
+
|
177
|
+
options = ARGV.getopts("y:", "m:") #引数付きショートネームオプションの指定
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
if options["y"] #もし"y"に値が入力されたら
|
182
|
+
|
183
|
+
puts year = options["y"].to_i #入力値をyear変数に代入
|
184
|
+
|
185
|
+
else
|
186
|
+
|
187
|
+
puts year = day.year #入力されないと今年のデータになる
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
if options["m"] #もし"m"に値が入力されたら
|
194
|
+
|
195
|
+
puts year = options["m"].to_i #入力値を今年をmonth変数に代入
|
196
|
+
|
197
|
+
else
|
198
|
+
|
199
|
+
puts year = day.mon #入力されないと今月のデータになる
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
head = Date.today.strftime("%B, %Y") #今月の月と西暦を取得
|
206
|
+
|
207
|
+
year = Date.today.year #今月の西暦
|
208
|
+
|
209
|
+
mon = Date.today.mon #今日の月
|
210
|
+
|
211
|
+
firstday = Date.new(year,mon, 1).wday #今月初めの日
|
212
|
+
|
213
|
+
lastday = Date.new(year,mon, -1).day #今月の最終日
|
214
|
+
|
215
|
+
week = %w(Su Mo Tu We Th Fr Sa) #配列を作る表記
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
puts head.center(20) #頭部分を中央寄せ
|
220
|
+
|
221
|
+
puts week.join(" ") #曜日の間隔を開けるように表示
|
222
|
+
|
223
|
+
print " " * firstday #1日までの空白を表示
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
wday = firstday
|
228
|
+
|
229
|
+
(1..lastday).each do |date| #(1..last...)で指定した範囲で繰り返し
|
230
|
+
|
231
|
+
print date.to_s.rjust(2) + " " #文字列に変換して日付を右寄せで表示
|
232
|
+
|
233
|
+
if Date.new(year,mon,date).wday == 6 #土曜(6)になったら改行する
|
234
|
+
|
235
|
+
puts "\n"
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
```
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
出力結果
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
```
|
250
|
+
|
251
|
+
% ruby calendar.rb -y 2030 -m 5
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
January, 2021
|
256
|
+
|
257
|
+
Su Mo Tu We Th Fr Sa
|
258
|
+
|
259
|
+
1 2
|
260
|
+
|
261
|
+
3 4 5 6 7 8 9
|
262
|
+
|
263
|
+
10 11 12 13 14 15 16
|
264
|
+
|
265
|
+
17 18 19 20 21 22 23
|
266
|
+
|
267
|
+
24 25 26 27 28 29 30
|
268
|
+
|
269
|
+
31 %
|
270
|
+
|
271
|
+
```
|
1
出力結果の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -120,6 +120,28 @@
|
|
120
120
|
|
121
121
|
```
|
122
122
|
|
123
|
+
出力結果
|
124
|
+
|
125
|
+
```
|
126
|
+
|
127
|
+
January, 2021
|
128
|
+
|
129
|
+
Su Mo Tu We Th Fr Sa
|
130
|
+
|
131
|
+
1 2
|
132
|
+
|
133
|
+
3 4 5 6 7 8 9
|
134
|
+
|
135
|
+
10 11 12 13 14 15 16
|
136
|
+
|
137
|
+
17 18 19 20 21 22 23
|
138
|
+
|
139
|
+
24 25 26 27 28 29 30
|
140
|
+
|
141
|
+
31
|
142
|
+
|
143
|
+
```
|
144
|
+
|
123
145
|
一番最後のスコープでこちらのコードをどのように修正すればいいか分からないので教えていただけますでしょうか?
|
124
146
|
|
125
147
|
```
|