LoginSignup
2
2

More than 5 years have passed since last update.

プロ生ちゃんのカレンダーのあれ (Ruby)

Last updated at Posted at 2015-01-06

プロ生ちゃんのこれ。
とっくに締め切り過ぎてますし今さらですが。

できるだけ厨二くさいのを書きたかった。

require 'date'

last = Date.new(Time.now.year, Time.now.month, -1)

days = (1..last.day).map{|d| '%2d' % d}
days.unshift *[nil] * (last + 1 << 1).wday

puts last.strftime "%B %Y"
puts days.each_slice(7).map{|week| week * "\t"}
January 2015
                 1   2   3
 4   5   6   7   8   9  10
11  12  13  14  15  16  17
18  19  20  21  22  23  24
25  26  27  28  29  30  31
  • Date.newは日付に-1を指定すると月末を取得できる
  • Date#+で別の日に移動できる (過去はマイナス)
  • Date#<<で別の月に移動できる (未来はマイナス)

  • 配列内で範囲オブジェクトに*をつけると展開できる

  • 配列 * 文字列でその文字列を各要素で挟んだ文字列を得られる

  • 配列をputsすると要素ごとに出力する

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2