Actions
Feature #10851
openIntroduce Regexp#fetch
Status:
Open
Assignee:
-
Target version:
-
Description
There is a common pattern in code:
match = pattern.match(string)
var = match && match[name_of_capture]
One should write it everywhere not to get an exception. It can be solved by introducing something like Hash#fetch.
class Regexp
def fetch(string, capture_name:, pos: nil, default_value: nil)
m = match(string, pos)
m ? m[capture_name] : default_value
end
end
No data to display
Actions
Like0