満年齢早見表

満年齢早見表

rubyです。どうでしょう?

  require 'date'
  this_year = Date.today.year
  def wareki(y)
     nengo_eiji_kanji = { 'M' => '明治',
                          'T' => '大正',
                          'S' => '昭和',
                          'H' => '平成',
                          'R' => '令和'}
     # 大晦日現在の年号を得る
     input = Date.new(y,12,31).jisx0301
     input = input.split(".") # ["R06", "12", "31"]
     nengo = input[0].split(//) # ["R", "0", "6"]
     nengo[0] = nengo_eiji_kanji[nengo[0]]
     nengo = nengo.join
  end
  def eto(y)
     eto = '子丑寅兎辰巳午未申酉戌亥'.split(//)
     eto = eto[y.modulo(12)-4]
  end
  120.times do |i|
     year = this_year - i
     # printf("%3d年前\t", i)
     # puts "#{year}年\t#{wareki(year)}年"
     # printf("%s年(%s) %d年 %3d歳\n" ,wareki(year), eto(year), year, i)
     printf("%d年 %s年(%s) %3d歳\n" ,year, wareki(year), eto(year), i)
  end