This folder contains leap year code snippets for Ruby.
-
library_leap_year?(year) -> bool
:- Utilizes date library's
Date.leap?
function to determine if a year is a leap year.
- Utilizes date library's
-
custom_leap_year?(year) -> bool
:- This function takes a year as input and returns
true
if the year is a leap year, andfalse
otherwise. - Leap Year Rules:
- A year is a leap year if it's divisible by 4.
- If the year is also divisible by 100, it must additionally be divisible by 400 to be a leap year.
- This function takes a year as input and returns
- Make sure you have Ruby installed on your system.
- Run the program using the following command:
ruby leap_year.rb
Testing library implementation:
Year 2000: true
Year 1900: false
Year 2024: true
Year 2023: false
Testing custom implementation:
Year 2000: true
Year 1900: false
Year 2024: true
Year 2023: false