Try'n'Go: The Last Date
Date#last_of_month takes either a Fixnum or a Time as argument.
require 'date' class Date def self.last_of_month( arg = Time.now ) year = ( arg.is_a? Fixnum ) ? Time.now.year : arg.year mon = ( arg.is_a? Fixnum ) ? arg : ( arg.mon rescue Time.now.mon ) raise ArgumentError unless mon.between?( 1, 12 ) begin; Date.new year, mon, mday ||= 31 rescue ArgumentError; mday -= 1; retry end end end