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

Comments

Projects
None yet
3 participants
@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

This comment has been minimized.

Show comment
Hide comment
@carlosantoniodasilva

carlosantoniodasilva May 13, 2012

Member

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?

Member

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

This comment has been minimized.

Show comment
Hide comment
@spastorino

spastorino May 13, 2012

Member

@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 :).

Member

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

This comment has been minimized.

Show comment
Hide comment
@carlosantoniodasilva

carlosantoniodasilva May 13, 2012

Member

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

Member

carlosantoniodasilva commented May 13, 2012

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

@joshuaclayton

This comment has been minimized.

Show comment
Hide comment
@joshuaclayton

joshuaclayton May 13, 2012

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

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

This comment has been minimized.

Show comment
Hide comment
@spastorino

spastorino May 14, 2012

Member

@joshuaclayton sorry for stealing your commit so :(

Member

spastorino commented May 14, 2012

@joshuaclayton sorry for stealing your commit so :(

@joshuaclayton

This comment has been minimized.

Show comment
Hide comment
@joshuaclayton

joshuaclayton May 14, 2012

@spastorino no worries, just glad it got fixed!

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