parse_arg(arg)
private
Parses arg and returns rest of arg and matched portion to
the argument pattern.
Yields when the pattern doesn’t match
substring.
Show source
def parse_arg(arg)
pattern or return nil, [arg]
unless m = pattern.match(arg)
yield(InvalidArgument, arg)
return arg, []
end
if String === m
m = [s = m]
else
m = m.to_a
s = m[0]
return nil, m unless String === s
end
raise InvalidArgument, arg unless arg.rindex(s, 0)
return nil, m if s.length == arg.length
yield(InvalidArgument, arg)
return arg[s.length..-1], m
end