Implement auto-tuple unpacking in block arguments, Rule 1 #2783
+356
−226
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is similar to #2778 but only Rule 1 (explained there) is implemented.
Additionally, an error is now given if more than expected block arguments are passed, as explained here.
Finally, the code has version checks so that in 0.18.0
Hash
will beEnumerable
, as well as a few other types (HTTP::Headers
,HTTP::Params
andENV
). These checks will disappear once we make a new release, but it allows us to avoid having to do an intermediate release that can use the new behaviour.I personally still like Rule 2 and see no harm in it, specially if combined with the error when extra block arguments are passed. Could be nice for
each_with_index
andeach_with_object
, when used on aHash
. But since there aren't many cases of that in the compiler (about ~6) and just a few in other projects I tried, maybe it's not very important.I'd still like to be able to do
hash.each { |key, value| ... }
instead ofhash.each { |(key, value)| ... }
, mostly because the later doesn't add any type safety, just noise. Basically, if I specify more arguments is because I'm expecting a tuple unpack to happen. If that's not the case (it's not a tuple), I get a compile error, so mistakes can't happen. With Rule 2 it's a bit more complicated because there are many more variants to consider.