Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

StringScanner#values_at

scanner.values_at( i1, i2, ... iN ) → an_array

Returns the subgroups in the most recent match at the given indices. If nothing was priorly matched, it returns nil.

Example
s = StringScanner.new("Fri Dec 12 1975 14:39")
s.scan(/(\w+) (\w+) (\d+) /)       # -> "Fri Dec 12 "
s.values_at 0, -1, 5, 2            # -> ["Fri Dec 12 ", "12", nil, "Dec"]
s.scan(/(\w+) (\w+) (\d+) /)       # -> nil
s.values_at 0, -1, 5, 2            # -> nil
See also #unscan #terminate also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0