modified Sequence to accept Enumerators #378

wants to merge 1 commit into


None yet

2 participants


I wanted do be able to do things like

sequence :hour, (1..12).cycle

and thought I'd check it you guys thought it might be useful.
I tried to implement it in a really non-intrusive way.

@joshuaclayton joshuaclayton added a commit that referenced this pull request May 13, 2012
@joshuaclayton joshuaclayton Sequences support Enumerators
This introduces an EnumeratorAdapter so everything coming in looks like
an Enumerator. It doesn't use the adapter if the #peek method exists on
the object.

This allows for sequences like:

    sequence(:cities, %w[Boston Atlanta Detroit Seattle].cycle)

This also makes it easier to cycle through arrays and ranges, since they
can be converted to Enumerators rather easily.

    sequence(:month, (1..12).to_enum)
    sequence(:month, %w[foo bar baz].to_enum)

This doesn't handle when calling Range#step out of the box, because
Ruby returns an Enumerator but ActiveSupport 3.x returns an array,
meaning #to_enum still needs to be called.

Closes #339, #378
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment