pub(crate) fn string_to_canonicalized_path(
    vm: &mut VM,
    string: Value,
    msg: &str,
) -> Result<PathBuf, RubyError> {
    let path = string_to_path(vm, string, msg)?;
    match path.canonicalize() {
        Ok(file) => Ok(file),
        Err(_) => Err(RubyError::argument(format!(
            "{} is an invalid filename. {:?}",
            msg, path
        ))),
    }
}
Convert Ruby String value`string` to canonicalized PathBuf.
ruruby/src/builtin/file.rs