[#107430] [Ruby master Feature#18566] Merge `io-wait` gem into core IO — "byroot (Jean Boussier)" <noreply@...>
Issue #18566 has been reported by byroot (Jean Boussier).
22 messages
2022/02/02
[ruby-core:107690] [Ruby master Feature#18596] Enhance the syntax for getting values in existing arrays.
From:
"Eregon (Benoit Daloze)" <noreply@...>
Date:
2022-02-21 17:56:17 UTC
List:
ruby-core #107690
Issue #18596 has been updated by Eregon (Benoit Daloze). Status changed from Open to Rejected > [1,2,3,4,5,6,7,8,9][2,-1] #result=nil,the expected result is from index 2 to the end Use `[1,2,3,4,5,6,7,8,9][2..-1]`. > Is it possible to add a third parameter to the array value syntax in order to simplify the syntax? Please no, Array#[] is already too complex and this is unnecessary and very unclear. You can use `[1,2,3,4,5,6,7,8,9][(2..8) % 2]` which already works and is clearer. ---------------------------------------- Feature #18596: Enhance the syntax for getting values in existing arrays. https://bugs.ruby-lang.org/issues/18596#change-96608 * Author: jackmaple (maple jack) * Status: Rejected * Priority: Normal ---------------------------------------- Hello everyone. Is it possible to enhance the value syntax in arrays, currently we can pass one or two parameters in the array to take values. ``` ruby [1,2,3,4,5,6,7,8,9][2] #result=3 [1,2,3,4,5,6,7,8,9][2,8] #result=[3, 4, 5, 6, 7, 8, 9] [1,2,3,4,5,6,7,8,9][-1] #result=9 ``` Although negative values are supported (from back to front), they are not supported as the second parameter. The following example is wrong and will not get the desired result. **Is it possible to make the second parameter also support negative values?** ``` ruby [1,2,3,4,5,6,7,8,9][2,-1] #result=nil,the expected result is from index 2 to the end ``` Sometimes we want to get interval values with step size. ``` ruby [1,2,3,4,5,6,7,8,9][(2..8).step(2)] #result=[3, 5, 7, 9] ``` **Is it possible to add a third parameter to the array value syntax in order to simplify the syntax?** for example: ``` ruby [1,2,3,4,5,6,7,8,9][2,8,2] #result=[3, 5, 7, 9] ``` thanks. -- https://bugs.ruby-lang.org/ Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>