Easy way to determine leap year in ruby?

MikeJ picture MikeJ · Oct 14, 2009 · Viewed 12.2k times · Source

Is there an easy way to determine if a year is a leap year?

Answer

Mitch Wheat picture Mitch Wheat · Oct 14, 2009

Use Date#leap?.

now = DateTime.now 
flag = Date.leap?( now.year ) 

e.g.

Date.leap?( 2018 ) # => false

Date.leap?( 2016 ) # => true