require "date" module M refine Integer do def sum to_s.chars.map(&:to_i).sum end end refine Date do def happy_day? month == day.sum end end end using M puts (Date.new(2015, 1, 1)..Date.new(2015, 12, 31)).select(&:happy_day?).count