Macro magnus::eval

source ·
macro_rules! eval {
    ($s:literal) => { ... };
    ($s:literal, $($rest:tt)*) => { ... };
}
Expand description

Evaluate a literal string of Ruby code with the given local variables.

Any type that implements Into<Value> can be passed to Ruby.

See also the eval function and Binding.

Examples

let result: i64 = magnus::eval!("a + b", a = 1, b = 2).unwrap();
assert_eq!(result, 3)
let a = 1;
let b = 2;
let result: i64 = magnus::eval!("a + b", a, b).unwrap();
assert_eq!(result, 3);