From: "Eregon (Benoit Daloze)" Date: 2022-03-23T14:41:26+00:00 Subject: [ruby-core:108042] [Ruby master Bug#18635] Enumerable#inject without block/symbol will return values or raise LocalJumpError Issue #18635 has been updated by Eregon (Benoit Daloze). I think either is fine. I think some methods raise LocalJumpError early, even if they didn't try to use the block yet, so LocalJumpError would also be reasonable. My view is the general form of #inspect is the block version, and the Symbol is just a shorthand for the block. So in that view LocalJumpError is a bit better. But either way, no code should do this so any of these exceptions is helpful. ---------------------------------------- Bug #18635: Enumerable#inject without block/symbol will return values or raise LocalJumpError https://bugs.ruby-lang.org/issues/18635#change-97002 * Author: bjfish (Brandon Fish) * Status: Open * Priority: Normal * ruby -v: 3.0.3 * Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- The following shows inconsistent behavior when no block/symbol are provided to inject. ``` ruby irb(main):002:0> {}.inject => nil irb(main):003:0> {one: 1}.inject => [:one, 1] irb(main):004:0> {one: 1, two: 2}.inject (irb):4:in `each': no block given (LocalJumpError) irb(main):005:0> [].inject => nil irb(main):006:0> [1].inject => 1 irb(main):007:0> [1, 2].inject (irb):7:in `each': no block given (LocalJumpError) ``` I would expect the results to be consistent by always raising a LocalJumpError or raising an ArgumentError when no block and symbol are given. -- https://bugs.ruby-lang.org/ Unsubscribe: