[#122258] [Ruby Misc#21367] Remove link to ruby-doc.org from www.ruby-lang.org/en/documentation/ — "p8 (Petrik de Heus) via ruby-core" <ruby-core@...>
Issue #21367 has been reported by p8 (Petrik de Heus).
11 messages
2025/05/23
[ruby-core:121799] [Ruby Feature#21300] Suggestion: Method for Array truncation
From:
"Eregon (Benoit Daloze) via ruby-core" <ruby-core@...>
Date:
2025-05-02 09:38:55 UTC
List:
ruby-core #121799
Issue #21300 has been updated by Eregon (Benoit Daloze). 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. ---------------------------------------- Feature #21300: Suggestion: Method for Array truncation https://bugs.ruby-lang.org/issues/21300#change-112864 * 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 -- [email protected] To unsubscribe send an email to [email protected] ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/