def days_in_month(month) (Date.new(Time.now.year,12,31).to_date<<(12-month)).day end
[nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]
The beauty of letting Ruby figure it out no doubt is the infamous February, so this might be better:
def days_in_month(year, month) (Date.new(year, 12, 31) << (12-month)).day end
def days_in_month(month) month == 2 ? 28 : 30 + ((month * 1.126).to_i % 2) end
require 'date' def days_in_month(year, month) (Date.new(year, 12, 31) << (12-month)).day end
You need to create an account or log in to post comments to this site.