module RegnalYear module JP refine Integer do def to_regnal_year_jp case self when 1868..1912 '明治' when 1912..1926 '大正' when 1926..1989 '昭和' when 1990..2019 # acutualy: 1/8/1989 - 4/30/2019 '平成' end end end end end using RegnalYear::JP pp 1988.to_regnal_year_jp # => "昭和" pp 2018.to_regnal_year_jp # => "平成"