I'm a React, Javascript & Rails full-stack Software Engineer. I have been working remotely for the past two years in a remote village. Before joining as a Software Engineer I founded kwiq - a hyperlocal delivery startup to deliver things in remote villages.
1 minute read
In Ruby, a Range is an object that represents a range of values with a defined beginning and end. It’s a fundamental data structure used to express a sequence or span between two values, whether they are numeric, alphabetical, or even dates.
We have two ways to define ranges.
reverse_each
The Range#reverse_each method is used to iterate through a range of values in reverse order.
Before
Using Range#reverse_each with very large or beginless or endless ranges never returns.
Under the hood Range#reverse_each uses Enumerable#reverse_each which is implemented with #to_a.
So we are virtually not able to use reverse_each for a very large or beginless or endless ranges, even if few elements are iterated on actually.
After
Ruby 3.3 adds Range#reverse_each for Integer elements, So we can use reverse_each for a very large or beginless ranges. Ref PR
With Ruby 3.3, Range#reverse_each for an endless range raises an exception, similar to Range#each for a beginless range. Ref PR