CARVIEW |
Select Language
HTTP/2 200
x-amz-id-2: 4zVAoDvozapYR/hW1RTVdNngQd/c7Jtv2fNIhHWgbDsUvxFGebj21MxRgJeGnol7k/pIIGcouiVTw3T83hQHhDo9ml5MqsDmgidxfEcVjuU=
x-amz-request-id: H1SXCNGBHJQ918A8
last-modified: Fri, 02 May 2025 08:41:15 GMT
etag: "4eb26aa6b75a7e00b9e07eda5f9023a1"
x-amz-server-side-encryption: AES256
server: AmazonS3
content-encoding: gzip
via: 1.1 varnish, 1.1 varnish
content-type: text/plain; charset=utf-8
accept-ranges: bytes
age: 0
date: Wed, 23 Jul 2025 20:24:46 GMT
x-served-by: cache-tyo11965-TYO, cache-bom-vanm7210060-BOM
x-cache: MISS, MISS
x-cache-hits: 0, 0
x-timer: S1753302286.271668,VS0,VE308
vary: Accept-Encoding
content-length: 567
From: "sigsys (Math Ieu) via ruby-core"
Date: 2025-05-02T08:31:27+00:00
Subject: [ruby-core:121798] [Ruby Feature#21300] Suggestion: Method for Array truncation
Issue #21300 has been reported by sigsys (Math Ieu).
----------------------------------------
Feature #21300: Suggestion: Method for Array truncation
https://bugs.ruby-lang.org/issues/21300
* Author: sigsys (Math Ieu)
* Status: Open
----------------------------------------
`#pop(n)` and `#slice!(...)` can be used for truncation, but they both allocate a new array for the deleted elements (unless you do it one at a time with `#pop()`...), which is not always needed.
I propose adding a `#size=` method for truncating without allocating a new array:
```
a = [10, 20, 30]
a.size = 2
a # [10, 20]
```
Growing the array could be allowed as well...
```
a = [10, 20]
a.size = 4
a # [10, 20, nil, nil]
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/