From: sawadatsuyoshi@... Date: 2014-11-06T08:01:31+00:00 Subject: [ruby-core:66114] [ruby-trunk - Feature #10482] Allow ignored items to vary in `Enumerable#chunk`. Issue #10482 has been updated by Tsuyoshi Sawada. Sorry, the example was wrong; I mistook `nil` and `NilClass`. But I hope you get the point. ---------------------------------------- Feature #10482: Allow ignored items to vary in `Enumerable#chunk`. https://bugs.ruby-lang.org/issues/10482#change-49824 * Author: Tsuyoshi Sawada * Status: Open * Priority: Normal * Assignee: * Category: * Target version: ---------------------------------------- In #5663, regarding a method proposed, Yehuda Katz's writes: ~~~ The only caveat is that it would be impossible to intentionally return nil here; suggestions welcome. ~~~ I would like to note here that the same problem exists with `Enumerable#chunk`. Currently, when the key value is `nil`, the corresponding items are thrown out. That may be useful sometimes, but sometimes, silently doing so causes a hard-to-detect bug. At least, there should be a way to change what is ignored (which would not break existing code using it), and ideally, nothing should be thrown out unless explicitly specified (which would break existing code). I propose `Enumerable#chunk` to take an optional named parameter `ignore`, which switches what is ignored. When something other than `nil` is specified, then `nil` should not be ignored: ~~~ruby [:foo1, :foo2, "bar", nil, nil].chunk(ignore: String){|e| e.class} # => [[Symbol, [:foo1, :foo2]], [NilClass, [nil, nil]]] ~~~ When you don't want anything to be ignored, then the parameter should be set to something that does not appear in the receiver: ~~~ruby [:foo1, :foo2, "bar", nil, nil].chunk(ignore: "nothing to ignore"){|e| e.class} # => [[Symbol, [:foo1, :foo2]], [String, ["bar"]], [NilClass, [nil, nil]]] ~~~ -- https://bugs.ruby-lang.org/