Skip to main content

define_global_function

Function define_global_function 

Source
pub fn define_global_function<M>(name: &str, func: M) -> Result<(), Error>
where M: Method,
👎Deprecated:

please use Ruby::define_global_function instead

Available on crate feature old-api only.
Expand description

Define a method in the root scope.

§Panics

Panics if called from a non-Ruby thread. See Ruby::define_global_function for the non-panicking version.

§Examples

use magnus::{define_global_function, function, rb_assert};

fn greet(subject: String) -> String {
    format!("Hello, {}!", subject)
}

define_global_function("greet", function!(greet, 1)).unwrap();
rb_assert!(r#"greet("world") == "Hello, world!""#);