pub(crate) fn replace_all(
        vm: &mut VM,
        regexp: Value,
        given: &str,
        replace: &str,
    ) -> Result<(String, bool), RubyError> {
        if let Some(s) = regexp.as_string() {
            let re = vm.regexp_from_escaped_string(&s)?;
            return re.replace_repeat(vm, given, replace);
        } else if let Some(re) = regexp.as_regexp() {
            return re.replace_repeat(vm, given, replace);
        } else {
            return Err(RubyError::argument("1st arg must be RegExp or String."));
        };
    }
Replaces all non-overlapping matches in `given` string with `replace`.
ruruby/src/builtin/regexp.rs