ruby-changes:65176
From: Nobuyoshi <ko1@a...>
Date: Sun, 7 Feb 2021 15:31:43 +0900 (JST)
Subject: [ruby-changes:65176] 947d93b715 (master): [DOC] {Array, MatchData}#values_at understand ranges [ci skip]
https://git.ruby-lang.org/ruby.git/commit/?id=947d93b715 From 947d93b715436b13eefa39f87737bdad3c1f870a Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sun, 7 Feb 2021 10:30:15 +0900 Subject: [DOC] {Array,MatchData}#values_at understand ranges [ci skip] --- array.c | 4 +++- re.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/array.c b/array.c index ad7e11a..07b3df0 100644 --- a/array.c +++ b/array.c @@ -3728,15 +3728,17 @@ append_values_at_single(VALUE result, VALUE ary, long olen, VALUE idx) https://github.com/ruby/ruby/blob/trunk/array.c#L3728 * array.values_at(*indexes) -> new_array * * Returns a new \Array whose elements are the elements - * of +self+ at the given \Integer +indexes+. + * of +self+ at the given \Integer or \Range +indexes+. * * For each positive +index+, returns the element at offset +index+: * a = [:foo, 'bar', 2] * a.values_at(0, 2) # => [:foo, 2] + * a.values_at(0..1) # => [:foo, "bar"] * * The given +indexes+ may be in any order, and may repeat: * a = [:foo, 'bar', 2] * a.values_at(2, 0, 1, 0, 2) # => [2, :foo, "bar", :foo, 2] + * a.values_at(1, 0..2) # => ["bar", :foo, "bar", 2] * * Assigns +nil+ for an +index+ that is too large: * a = [:foo, 'bar', 2] diff --git a/re.c b/re.c index 9964e29..4be5e8b 100644 --- a/re.c +++ b/re.c @@ -2077,6 +2077,7 @@ match_aref(int argc, VALUE *argv, VALUE match) https://github.com/ruby/ruby/blob/trunk/re.c#L2077 * m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie") * m.to_a #=> ["HX1138", "H", "X", "113", "8"] * m.values_at(0, 2, -2) #=> ["HX1138", "X", "113"] + * m.values_at(1..2, -1) #=> ["H", "X", "8"] * * m = /(?<a>\d+) *(?<op>[+\-*\/]) *(?<b>\d+)/.match("1 + 2") * m.to_a #=> ["1 + 2", "1", "+", "2"] -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/