Learn and Learn

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

Ruby – Find Block Iterates Evaluation – step Method with Examples

In Ruby step method iterates evaluation of the given block, which takes a date object. The limit should be a date object. For example,



NOTE: From the above example, it is easy to understand that .step method iterates until it find the required day which is also indicated in the code. This code tells that, this is the first monday of that particular year.

Syntax of step Method in Ruby


Parameter of step Method in Ruby

x – where x is any valid date object. This parameter is required.

Error Handling of step Method in Ruby

If the x parameter is not a valid date object the step method will return an error and it could be due to the wrong format of the date in a code, the use of zero or the missing of any other character.

Return Value of step Method in Ruby

The step method will return the number of the special day indicated in the code from the whole year like this is the 2nd, 10th or 15th monday of that year.

Ruby step Method Example


Ruby Different Methods of step


Use of Step Method in Ruby with Example


LearnAndLearn.com © 2018 - All rights reserved