CARVIEW |
Select Language
HTTP/2 200
cache-control: max-age=0, private, must-revalidate
content-type: text/html; charset=utf-8
etag: W/"bdbbcb0d264ca61358f6a7f5638ee829"
nel: {"report_to":"heroku-nel","response_headers":["Via"],"max_age":3600,"success_fraction":0.01,"failure_fraction":0.1}
referrer-policy: strict-origin-when-cross-origin
report-to: {"group":"heroku-nel","endpoints":[{"url":"https://nel.heroku.com/reports?s=hjCey2TOnvgI4Ic%2Bb4RnwsL5JQarPQ7sUmjNL%2FHBA6s%3D\u0026sid=e11707d5-02a7-43ef-b45e-2cf4d2036f7d\u0026ts=1753255971"}],"max_age":3600}
reporting-endpoints: heroku-nel="https://nel.heroku.com/reports?s=hjCey2TOnvgI4Ic%2Bb4RnwsL5JQarPQ7sUmjNL%2FHBA6s%3D&sid=e11707d5-02a7-43ef-b45e-2cf4d2036f7d&ts=1753255971"
server: Heroku
set-cookie: _redmine_session=QkIyN3pBT1JYYTJ5WmdaN1V1a2ZiUW90b1lVeWpRNXdDSDkyelV0cjVpL3BSM2dnUlhpWU50MnBHYUFJZE9HTUdrbkxGUUJzSXZWclpJaE9JUm83VFlvY2FWVFZhMnROTXUwemRlNlJ5T2hqZi9Ea0FZSnFqNmE0WllTU3hjOXJIYVArc0YxVmpvbjh4blFUZ3I3akdrVXFFdjlXM2I0SUdRc2Z4VHIzSlBSOUc1a1JBNzNWVEIwWjdZdDJjS0t2LS1FSnN4aGpOQUh0c25OWlRwL1dsL0R3PT0%3D--ff48dcbfd3f62c5f5edec986ebcc65f0c1174063; path=/; secure; httponly; samesite=lax
strict-transport-security: max-age=63072000; includeSubDomains
vary: Accept
via: 2.0 heroku-router
x-content-type-options: nosniff
x-download-options: noopen
x-frame-options: SAMEORIGIN
x-permitted-cross-domain-policies: none
x-request-id: 341a3bd5-eb84-9296-614f-1ede66cdec8a
x-runtime: 0.071328
x-xss-protection: 1; mode=block
content-length: 25802
date: Wed, 23 Jul 2025 07:32:51 GMT
Feature #21300: Suggestion: Method for Array truncation - Ruby - Ruby Issue Tracking System
[ruby-core:121798]
Project
General
Profile
Tags
Custom queries
Actions
Feature #21300
openSuggestion: Method for Array truncation
Added by sigsys (Math Ieu) 3 months ago. Updated 3 months ago.
Status:
Open
Assignee:
-
Target version:
-
Description
#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]
Updated by Eregon (Benoit Daloze) 3 months ago
Using ary.size =
feels unidiomatic Ruby to me, it feels very low level and not very expressive about the intent (e.g. it's not clear if shrinking or growing).
I don't think pop(n) returning an Array is big overhead, i.e., I don't think there is enough reason to add another Array method for this rarely-needed case.
Actions
Like0
Like0
Powered by Redmine © 2006-2025 Jean-Philippe Lang
Loading...