Skip to content
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

Implement Range#reverse_each #2427

Merged
merged 2 commits into from
Dec 27, 2024
Merged

Conversation

FnControlOption
Copy link
Contributor

Implementation:

def reverse_each
  raise TypeError, "can't iterate from #{self.end.class}" if self.end.nil?
  return super unless self.end.respond_to?(:pred)
  return enum_for(:reverse_each) { size } unless block_given?
  item = self.end
  item = item.pred if exclude_end?
  while self.begin.nil? || item >= self.begin
    yield item
    item = item.pred
  end
  self
end

@seven1m seven1m merged commit c37608c into natalie-lang:master Dec 27, 2024
17 checks passed
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