pub(crate) fn replace_one(
        vm: &mut VM,
        re_val: Value,
        given: &str,
        replace: &str,
    ) -> Result<String, RubyError> {
        if let Some(s) = re_val.as_string() {
            let re = vm.regexp_from_escaped_string(&s)?;
            re.replace_once(vm, given, replace).map(|x| x.0)
        } else if let Some(re) = re_val.as_regexp() {
            re.replace_once(vm, given, replace).map(|x| x.0)
        } else {
            Err(RubyError::argument("1st arg must be RegExp or String."))
        }
    }
Replaces the leftmost-first match with `replace`.
ruruby/src/builtin/regexp.rs