Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

カレンダーのプログラムを解く #4

Open
itume opened this issue Oct 19, 2019 · 2 comments
Open

カレンダーのプログラムを解く #4

itume opened this issue Oct 19, 2019 · 2 comments
Labels
Projects

Comments

@itume
Copy link
Collaborator

itume commented Oct 19, 2019

今月のカレンダーを表示するプログラムを書く。(コマンドラインのプログラムとして作る)
macに入っているcalコマンドと同じ見た目で作る。
また、-mで月を、-yで年を指定できるように。(指定しない場合は今月・今年)
少なくとも1970年から2100年までは表示できること。

今月の最初の日と最後の日を求めて、最初の日から最後の日まで順番に表示すると良い。土曜日を表示した後に改行を入れれば大体完成。
-1日は当月の最終日を指します。
date = Date.new(2010, 5, -1)
改行無しで出力したい場合はprintを使うと良い。

解いたらfjordに提出する

@itume itume added the 1.0 label Oct 19, 2019
@itume itume added this to やること in 復習 via automation Oct 19, 2019
@itume itume moved this from やること to 今週やること in 復習 Oct 19, 2019
@tararico tararico moved this from 今週やること to 作業中 in 復習 Oct 29, 2019
@tararico
Copy link
Owner

学んだこと

  • Dateクラス
    Date.new(year,mon, -1)でその月の最終日がでる
  • joinメソッドは、配列の各要素を文字列に変換し、引数sepを区切り文字として結合した文字列を返す。
array.join(sep = $,)
week = ["日", "月", "火", "水", "木", "金", "土"]
puts week.join(" ")
=> 日 月 火 水 木 金 土
  • putsとprintの違い

    • putsは改行が入る。printは改行しない。
  • centerメソッドは、引数lengthの長さを持つ新しい文字列を作成し、レシーバstrの文字列をその中央に置いて、左右を空白で埋める。

s = "hello"
p s.center(15)
=> "     hello     "
  • rjustメソッドは長さ width の文字列に self を右詰めした文字列を返す。 self の長さが width より長い時には元の文字列の複製を返す。
p "foo".rjust(10)        # => "       foo"
p "foo".rjust(2)         # => "foo"

@tararico tararico moved this from 作業中 to 完了 in 復習 Nov 11, 2019
@tararico
Copy link
Owner

オプション -a, -b を受け付けるコマンドを作成するには
optparseを使えば良い

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
復習
  
完了
Development

No branches or pull requests

2 participants