Skip to content

Instantly share code, notes, and snippets.

@yancya
Last active December 21, 2015 01:29
Show Gist options
  • Save yancya/6228365 to your computer and use it in GitHub Desktop.
Save yancya/6228365 to your computer and use it in GitHub Desktop.
連続した年月の文字列を出力する
# rjust をいつも忘れる
(2011..2013).each{|y| (1..12).each{|m| print [y.to_s, m.to_s.rjust(2, "0")].join('-') + ' '}}
# こっちの方がスマートかも
(2011..2013).to_a.product((1..12).map{|n| n.to_s.rjust(2, "0")}).map{|a| a.join("-")}.join(" ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment