From: "matz (Yukihiro Matsumoto)" Date: 2013-03-27T12:26:26+09:00 Subject: [ruby-core:53763] [ruby-trunk - Feature #8172][Feedback] IndexError-returning counterparts to destructive Array methods Issue #8172 has been updated by matz (Yukihiro Matsumoto). Status changed from Open to Feedback I am not against the idea itself, but using bang (!) for the names is not consistent with other bang methods. Matz. ---------------------------------------- Feature #8172: IndexError-returning counterparts to destructive Array methods https://bugs.ruby-lang.org/issues/8172#change-37961 Author: sawa (Tsuyoshi Sawada) Status: Feedback Priority: Normal Assignee: Category: Target version: =begin There are a few desctructive (({Array})) methods that take an index as an argument and silently insert (({nil})) if the index is out of range: a = []; a[1] = :foo; a # => [nil, :foo] [].insert(1, :foo) # => [nil, :foo] [].fill(:foo, 1, 1) # => [nil, :foo] Among them, (({Array#[]})) has a counterpart that returns an (({IndexError})) when the index is out of range: [].fetch(1) # => IndexError and this is useful to avoid bugs that would be difficult to find if (({Array#[]})) were used. However for (({Array#insert})) and (({Array#fill})), there are no such counterparts, and that fact that these methods silently insert (({nil})) is often the cause of a bug that is difficult to find. I suggest there should be some versions of these methods that return (({IndexError})) when index is out of range: [].insert!(1, :foo) # => IndexError [].fill!(:foo, 1, 1) # => IndexError I believe this would make debugging easier. =end -- http://bugs.ruby-lang.org/