How to get the number of days in a given month in Ruby, accounting for year?

Viewed 46635

I'm sure there's a good simple elegant one-liner in Ruby to give you the number of days in a given month, accounting for year, such as "February 1997". What is it?

13 Answers

For a given Date object I feel like the easiest is:

Date.today.all_month.count

Since the time is irrelevant for this purpose then you just need a date object:

[*Date.today.all_month].size
Related