Project

General

Profile

Actions

Bug #18635

closed

Enumerable#inject without block/symbol will return values or raise LocalJumpError

Added by bjfish (Brandon Fish) over 2 years ago. Updated over 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:107911]

Description

The following shows inconsistent behavior when no block/symbol are provided to inject.

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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0