Skip to content

Instantly share code, notes, and snippets.

@avdi
Created January 9, 2015 20:32
Show Gist options
  • Save avdi/d9d92640e570fcba2988 to your computer and use it in GitHub Desktop.
Save avdi/d9d92640e570fcba2988 to your computer and use it in GitHub Desktop.
Behold, the null enumerator.
e = loop
e # => #<Enumerator: main:loop>
e.next # => nil
e.next # => nil
e.peek # => nil
e.size # => Infinity
e.rewind
e.next # => nil
@AaronLasseigne
Copy link

@Peeja

[5].cycle

@avdi
Copy link
Author

avdi commented Jan 9, 2015

Nice.

@Peeja
Copy link

Peeja commented Jan 12, 2015

@AaronLasseigne Ooh, very nice.

@avdi That's interesting. It's a shame #with_object doesn't use use #next_values. I wonder if Ruby would accept a patch for it…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment