Ruby – Get the Gregorian Leap Year – gregorian_leap?() Method with Examples

The gregorian leap method returns true if in the year in the given code is a leap year of the proleptic Gregorian Calendar and false if not. The leap year comes after every 4 years. To get the Gregorian leap year you can use Date.gregorian_leap?() method.

gregorian_leap?() Method in Ruby

gregorian_leap?() method exists in Standard Date Library of Ruby. The purpose of this method is to get leap year from proleptic Gregorian Calendar.

 

Syntax of the gregorian_leap?() Method in Ruby

In date, the syntax of gregorian_leap?() method is:

Date.gregorian_leap?(x)

 

Parameter of gregorian_leap?() Method in Ruby

The parameter x is any valid gregorian date object. This parameter is required.Note: If the x parameter is not a valid gregorian date object gregorian_leap?() method will return an error.

 

Return Value of gregorian_leap?()

gregorian_leap?() method return the true if the year mentioned in the code is a leap year of proleptic Gregorian Calendar.

 

Ruby – Get the gregorian_leap?() Year Example 1

# import date library
require 'date'
x = Date.gregorian_leap?(2012)
puts x

Output
true

 

Ruby – Get the gregorian_leap?() Year Example 2

# import date library
require 'date'
x = Date.gregorian_leap?(2013)
puts x

Output
false

 

Ruby – Get the gregorian_leap?() Year Example 3

# import date library
require 'date'
x = Date.gregorian_leap?(2014)
puts x

Output
false

 

Ruby – Get the gregorian_leap?() Year Example 4

# import date library
require 'date'
x = Date.gregorian_leap?(2016)
puts x

Output
true