Sha256: 4db707fbad7b2ae94911f1b631955953bc2580e9f8bcafadcfe2fd0e4208675f

Contents?: true

Size: 957 Bytes

Versions: 2

Compression:

Stored size: 957 Bytes

Contents

use ruru::{RString, Object, Class, AnyObject};
use debug::RubyDebugInfo;

#[inline]
pub fn is_same_path(a: &str, b: &str) -> bool {
  if cfg!(windows) {
    a.to_uppercase() == b.to_uppercase()
  } else {
    a == b
  }
}

pub fn anyobject_to_string(item: AnyObject) -> Result<String, RubyDebugInfo> {
  let result = &item;
  if Class::from_existing("String").case_equals(result) {
    return Ok(RString::from(result.value()).to_string())
  }
  
  if Class::from_existing("Pathname").case_equals(result) {
    return Ok(result.instance_variable_get("@path").
      try_convert_to::<RString>().
      unwrap_or(RString::new("")).
      to_string())
  }
  
  if result.respond_to("to_path") {
    return Ok(Class::from(result.send("to_path", None).value()).
      instance_variable_get("@path").
      try_convert_to::<RString>().
      unwrap_or(RString::new("")).
      to_string())
  }

  Ok(RString::from(result.send("to_s", None).value()).to_string())
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
faster_path-0.3.1 src/helpers.rs
faster_path-0.2.6 src/helpers.rs