macro_rules! rb_assert { ($expr:literal) => { ... }; ($expr:literal, $($bindings:tt)*) => { ... }; ($ruby:expr, $expr:literal) => { ... }; ($ruby:expr, $expr:literal, $($bindings:tt)*) => { ... }; }
Expand description
Asserts a Ruby expression evaluates to a truthy value.
This macro uses the Ruby
power_assert
gem that is part of
the Ruby standard library to generate detailed failure messages.
ⓘ
magnus::rb_assert!("1 + 2 == 4");
Outputs:
thread 'main' panicked at '
1 + 2 == 4
| |
| false
3', src/lib.rs:5:1
§Panics
Panics if called from a non-Ruby thread.
§Examples
magnus::rb_assert!("1 + 2 == 3");
Passing Ruby
to avoid the Ruby thread check:
let ruby = magnus::Ruby::get().unwrap();
magnus::rb_assert!(ruby, "1 + 2 == 3");
Making local variables accessible to Ruby:
let a = 1;
let b = 2;
magnus::rb_assert!("a + b == 3", a, b);
Directly setting local variables:
magnus::rb_assert!("a + b == 3", a = 1, b = 2);