Macro rb_sys::rb_intern

source ·
macro_rules! rb_intern {
    ($s:literal) => { ... };
}
Expand description

Finds or creates a symbol for the given static string. This macro will memoize the ID to avoid repeated calls to libruby. You should prefer this macro over [rb_intern3] when the string is known at compile time.

§Safety

This macro is safe under two conditions:

  • Ruby VM is initialized and that thus safe to call into libruby
  • The first call to this macro will be done inside of a managed Ruby thread (i.e. not a native thread)

§Example

use rb_sys::{symbol::rb_intern, rb_funcall, rb_utf8_str_new};

unsafe {
  let reverse_id = rb_intern!("reverse");
  let msg = rb_utf8_str_new("nice one".as_ptr() as *mut _, 4);
  rb_funcall(msg, reverse_id, 0);
}