[#62904] [ruby-trunk - Feature #9894] [Open] [RFC] README.EXT: document rb_gc_register_mark_object — normalperson@...
Issue #9894 has been reported by Eric Wong.
3 messages
2014/06/02
[#63321] [ANN] ElixirConf 2014 - Don't Miss Jos辿 Valim and Dave Thomas — Jim Freeze <jimfreeze@...>
Just a few more weeks until ElixirConf 2014!
6 messages
2014/06/24
[#63391] Access Modifiers (Internal Interfaces) — Daniel da Silva Ferreira <danieldasilvaferreira@...>
Hi,
3 messages
2014/06/28
[ruby-core:63202] [ruby-trunk - Feature #9948] Safely insert an object into an array
From:
nobu@...
Date:
2014-06-17 00:59:19 UTC
List:
ruby-core #63202
Issue #9948 has been updated by Nobuyoshi Nakada.
Description updated
"safely" sounds too vague.
----------------------------------------
Feature #9948: Safely insert an object into an array
https://bugs.ruby-lang.org/issues/9948#change-47253
* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee:
* Category:
* Target version:
----------------------------------------
When I insert an object using `Array#insert(index, object)` method (or `Array#[index]= object`), it happened sometimes that I mistakenly passed `index` that is too big, and too often in such cases was the bug very difficult to detect because in such case, `insert` will silently insert `nil` to fill up the empty slots:
~~~ruby
[:foo, :bar].insert(4, :baz) # => [:foo, :bar, nil, nil, :baz]
~~~
On the other hand, when the index is too small (negative), `index` raises an index error. I wish that an error were raised when the index is too big (when `index` is greater than `length` of `self`), but it is perhaps a bad idea to change the feature of `insert` by now. So I propose that a new method being added, something like `Array#safely_insert`, which works the same as `insert`, except that when `index` is larger than the size of the array, it should raise:
Index Error: index #{indexs} too large for array; maximum: #{length}
--
https://bugs.ruby-lang.org/