Skip to main content
Post Made Community Wiki
Source Link
horseyguy
  • 30k
  • 20
  • 109
  • 151

Use a Range object as an infinite lazy list:

Inf = 1.0 / 0

(1..Inf).take(5) #=> [1, 2, 3, 4, 5]

More info here: http://banisterfiend.wordpress.com/2009/10/02/wtf-infinite-ranges-in-ruby/