Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

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:

 

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


Output
true

 

Ruby – Get the gregorian_leap?() Year Example 2


Output
false

 

Ruby – Get the gregorian_leap?() Year Example 3


Output
false

 

Ruby – Get the gregorian_leap?() Year Example 4


Output
true

 

LearnAndLearn.com © 2018 - All rights reserved