Skip to content

added calendar code#2

Open
rani-i3 wants to merge 3 commits into
mainfrom
ranicalendar
Open

added calendar code#2
rani-i3 wants to merge 3 commits into
mainfrom
ranicalendar

Conversation

@rani-i3

@rani-i3 rani-i3 commented Aug 29, 2023

Copy link
Copy Markdown
Owner

No description provided.

@JunichiIto JunichiIto left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コメントしました〜。

Comment thread 02.calendar/calendar.rb Outdated
require 'date'
require 'optparse'

# コマンドラインでparseする

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread 02.calendar/calendar.rb Outdated

# date enumeratorを作る
date_range = Date.new(year, month, 1)..Date.new(year, month, -1)
dates_enum = date_range.to_enum

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_enumせずにRangeオブジェクトのままでもカレンダープログラムは作れるはずです。
困ったことが出てきたら、RangeクラスのAPIドキュメントを調べてみてください〜。

Comment thread 02.calendar/calendar.rb Outdated
puts if date.saturday?
end

puts "\n"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

puts自身が改行してくれるので、改行文字をputsする必要はないです〜。

Comment thread 02.calendar/calendar.rb Outdated
dates_enum = date_range.to_enum

# カレンダーを表示する
puts "\n#{Date::MONTHNAMES[month]} #{year}".center(20)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

スクショを見ると中央寄せになってないように見えました。
スクショが古いんでしょうか?

Comment thread 02.calendar/calendar.rb Outdated
end

puts "\n"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要な空行です。

Comment thread 02.calendar/calendar.rb
date_range = Date.new(year, month, 1)..Date.new(year, month, -1)

calendar_title = "#{month}月 #{year}"
puts calendar_title.center(20)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

スクショを見るとcenterの意味がないように見えますね。

Screenshot 2023-09-05 at 11 30 59

OSのcalコマンドを実行して、それと同じ見た目になるように修正してみてください。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ああーそれは古いスクショだと思います。今のコードの状態だと、こういう形になりました:
Screenshot 2023-09-05 at 11 49 26
centerとかrjustを使いたいと思いましたが、結局同じ結果なのでcenterにしました。

@JunichiIto JunichiIto left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確認しました!OKです〜🙆‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants