回答編集履歴
1
追記しました。
test
CHANGED
@@ -5,3 +5,107 @@
|
|
5
5
|
if Date.new(year,mon,date).wday == 6
|
6
6
|
|
7
7
|
に変えてください。
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
```Ruby
|
14
|
+
|
15
|
+
require "date"
|
16
|
+
|
17
|
+
require 'optparse'
|
18
|
+
|
19
|
+
day = Date.today
|
20
|
+
|
21
|
+
options = ARGV.getopts("y:", "m:")
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
if options["y"]
|
26
|
+
|
27
|
+
year = options["y"].to_i
|
28
|
+
|
29
|
+
else
|
30
|
+
|
31
|
+
year = day.year
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
if options["m"]
|
38
|
+
|
39
|
+
month = options["m"].to_i
|
40
|
+
|
41
|
+
else
|
42
|
+
|
43
|
+
month = day.mon
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
head = Date.today.strftime("%B, %Y")
|
50
|
+
|
51
|
+
year = Date.today.year
|
52
|
+
|
53
|
+
mon = Date.today.mon
|
54
|
+
|
55
|
+
firstday = Date.new(year,mon, 1).wday
|
56
|
+
|
57
|
+
lastday = Date.new(year,mon, -1).day
|
58
|
+
|
59
|
+
week = %w(Su Mo Tu We Th Fr Sa)
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
puts head.center(20)
|
64
|
+
|
65
|
+
puts week.join(" ")
|
66
|
+
|
67
|
+
print " " * firstday
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
wday = firstday
|
72
|
+
|
73
|
+
(1..lastday).each do |date|
|
74
|
+
|
75
|
+
print date.to_s.rjust(2) + " "
|
76
|
+
|
77
|
+
if Date.new(year,mon,date).wday == 6
|
78
|
+
|
79
|
+
puts "\n"
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
実行結果
|
92
|
+
|
93
|
+
```Ruby結果
|
94
|
+
|
95
|
+
January, 2021
|
96
|
+
|
97
|
+
Su Mo Tu We Th Fr Sa
|
98
|
+
|
99
|
+
1 2
|
100
|
+
|
101
|
+
3 4 5 6 7 8 9
|
102
|
+
|
103
|
+
10 11 12 13 14 15 16
|
104
|
+
|
105
|
+
17 18 19 20 21 22 23
|
106
|
+
|
107
|
+
24 25 26 27 28 29 30
|
108
|
+
|
109
|
+
31
|
110
|
+
|
111
|
+
```
|