-
Notifications
You must be signed in to change notification settings - Fork 605
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
Accept a nil argument for Array#flatten. #3175
Conversation
In order to mirror MRI's behaviour, nil is allowed as the argument of Array#flatten and Array#flatten!. It is treated as -1 which means endless recursive flatenning of the Array.
While the C source code of MRI explicitly checks for a nil value (http://rxr.whitequark.org/mri/source/array.c#4284) I suspect this is an artifact of the C function taking a variable number of arguments (http://rxr.whitequark.org/mri/source/array.c#5548, -1 indicates a variable argument number). Looking at the tests for If this is an artifact, and not a design choice, I don't think this would be something we'd want to merge in. I checked JRuby 1.7.12's behaviour and that currently matches Rubinius' behaviour. In case this is something we do want to merge the spec changes would have to be extracted into a separate commit. Doing so makes it much easier to synchronize these changes back into RubySpec (said process is already painful enoguh). |
I agree that Who decides in such matters? |
Send a pull request / fix to the gem in question. |
Thanks. If so - you may close this or mark it as "won't fix" / "not a bug". |
Hm, I'd be interested in knowing what the rationale would be for using |
https://github.com/hamstergem/hamster/blob/master/lib/hamster/vector.rb#L425 - in this case, modifying the default value for the method argument from |
@dubek Ah, yeah it seems the only reason I'll close this pull request then, feel free to re-open whenever needed. |
FWIW, someone should file a bug with MRI that 1. clarifies the documentation (I don't see any mention of -1 in |
MRI bug report regarding |
@dubek thanks! |
In order to mirror MRI's behaviour, nil is allowed as the argument of
Array#flatten and Array#flatten!. It is treated as -1 which means
endless recursive flatenning of the Array.
MRI:
Rubinius 2.3.0 before this fix:
OS: