Skip to content

Instantly share code, notes, and snippets.

@briandailey
Created September 27, 2012 19:58
Show Gist options
  • Select an option

  • Save briandailey/3796133 to your computer and use it in GitHub Desktop.

Select an option

Save briandailey/3796133 to your computer and use it in GitHub Desktop.
method to check a year to see if it's a leap year.
def leap(year)
false
true if year % 4 == 0
false if year % 100 == 0
true if year % 400 == 0
end
This will return true if the year is a multiple of 400. Otherwise it returns nil.
--Working version --
def leap_year?(year)
if year % 400 == 0
true
elsif year % 100 == 0
false
elsif year % 4 == 0
true
else
false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment