Feature #2172
closed
Enumerable#chunk with no block
Added by marcandre (Marc-Andre Lafortune) about 15 years ago.
Updated about 8 years ago.
Description
=begin
What should "(1..3).chunk" (i.e. without a block) do?
It issued an
ArgumentError: tried to create Proc object without a block
I changed the error message to "no block given" which I hope to be more informative, but maybe there is something more useful to do here?
A default block of {|x| x} doesn't seem all that useful.
Returning an enumerator that, upon completion, will return an enumerator would probably be better, but could also be a bit confusing if someone doesn't realize he forgot to specify the block?
Thanks to Run Paint for raising the question when writing the rubyspec for #chunk.
=end
- Status changed from Open to Assigned
- Assignee changed from matz (Yukihiro Matsumoto) to akr (Akira Tanaka)
- Category set to core
- Assignee changed from akr (Akira Tanaka) to matz (Yukihiro Matsumoto)
- Target version set to 1.9.2
- Assignee changed from matz (Yukihiro Matsumoto) to akr (Akira Tanaka)
- Target version changed from 1.9.2 to 2.0.0
Any decision about this? For me it's a clear +1, chunking by the values unchanged is very common (not that it's representative, but I checked my code: 4 ocurrences of chunk, all with the identity block)
- Description updated (diff)
- Target version changed from 2.0.0 to 2.6
- Assignee changed from akr (Akira Tanaka) to matz (Yukihiro Matsumoto)
Forgot to note that the other possiblity suggested for chunk
with no block can now be done clearly and succintly with chunk(&:itself)
, so there's no longer any doubt that the block without block should return an Enumerator
Now it sounds reasonable. Marc-Andre, could you implement it?
Matz.
Great, thanks!
Done for chunk
.
Matz, I imagine I should do the same for chunk_while
, slice_after
, slice_before
and slice_when
, right?
- Status changed from Assigned to Closed
Closing, created #12813 instead.
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0