macro_rules! eval { ($str:literal) => { ... }; ($str:literal, $($bindings:tt)*) => { ... }; ($ruby:expr, $str:literal) => { ... }; ($ruby:expr, $str:literal, $($bindings:tt)*) => { ... }; }
Expand description
Evaluate a literal string of Ruby code with the given local variables.
Any type that implements IntoValue
can be passed to Ruby.
See also the eval
function and Binding
.
§Panics
Panics if called from a non-Ruby thread.
§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);