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

Range#step behavior is different from core Ruby #6297

Closed
joshuaclayton opened this issue May 13, 2012 · 6 comments
Closed

Range#step behavior is different from core Ruby #6297

joshuaclayton opened this issue May 13, 2012 · 6 comments
Labels

Comments

@joshuaclayton
Copy link

@joshuaclayton joshuaclayton commented May 13, 2012

When calling Range#step without a block, instead of returning an Enumerator, an array is returned. Why is this? I'm all for ActiveSupport extending behavior of core Ruby libraries, but to completely change the value that's returned seems wrong.

If this can't be changed, is there a way to opt out of this specific behavior?

>> (0..10).step(2)
=> #<Enumerator: 0..10:step(2)>
>> require 'active_support/core_ext'
=> true
>> (0..10).step(2)
=> [0, 2, 4, 6, 8, 10]
@carlosantoniodasilva
Copy link
Member

@carlosantoniodasilva carlosantoniodasilva commented May 13, 2012

According to the code, it overrides Range#step to handle the case without blocks. I don't know why this code was added before, but could be to handle some weird Ruby cases in older versions, where it didn't handle this method without a block. This commit 99c6482 added it 5 years ago.

There's no way to opt-out of this particular behavior, unless you require all stuff you want manually. Anyway, I believe the monkey patch could be removed, as one could just call to_a yourself if required.

@jeremy thoughs on this one?

@spastorino
Copy link
Member

@spastorino spastorino commented May 13, 2012

@carlosantoniodasilva @jeremy I've just seen your comment Carlos. For me the blockless_step.rb code doesn't make sense anymore. If you feel that I'm wrong feel free to revert it :).

@carlosantoniodasilva
Copy link
Member

@carlosantoniodasilva carlosantoniodasilva commented May 13, 2012

I'm just fine with the removal, thanks bro :)

@joshuaclayton
Copy link
Author

@joshuaclayton joshuaclayton commented May 13, 2012

You guys are damn fast! I was going to make a pull request if everyone agreed it could be removed; thanks!

@spastorino
Copy link
Member

@spastorino spastorino commented May 14, 2012

@joshuaclayton sorry for stealing your commit so :(

@joshuaclayton
Copy link
Author

@joshuaclayton joshuaclayton commented May 14, 2012

@spastorino no worries, just glad it got fixed!

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.