Skip to content

Range#step: restore legacy behavior for String ranges #11454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2024

Conversation

zverok
Copy link
Contributor

@zverok zverok commented Aug 25, 2024

See discussion in https://bugs.ruby-lang.org/issues/18368#note-34

Of options I’ve named I implemented support for String ranges for both old and new behavior:

# Old behavior with integer steps and #succ
('a'..).step(2).take(3)
#=> ["a", "c", "e"]
('a'..).step.take(3)
#=> ["a", "b", "c"]

# New behavior with string step and #+
('a'..).step('b').take(3)
#=> ["a", "ab", "abb"]

@zverok zverok self-assigned this Aug 25, 2024
@zverok zverok requested review from knu and mame August 25, 2024 18:13
Copy link
Member

@knu knu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. The functions step_i_iter() and step_i() are exactly what existed before the change, so this PR accurately tries to resurrect the lost compatibility.

You could do the same for symbols. What do you think?

@knu knu merged commit 245ed2f into ruby:master Sep 3, 2024
112 checks passed
@zverok zverok deleted the range-string-step branch September 8, 2024 14:36
@zverok
Copy link
Contributor Author

zverok commented Sep 8, 2024

You could do the same for symbols. What do you think?

@knu, sorry, it took me some time to find a minute to work on this.

Here we go: #11573

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants