Function magnus::current_receiver
source · pub fn current_receiver<T>() -> Result<T, Error>where
T: TryConvert,
Expand description
Return the Ruby self
of the current method context.
Returns Err
if called outside a method context or the conversion fails.
§Panics
Panics if called from a non-Ruby thread. See Ruby::current_receiver
for
the non-panicking version.
§Examples
use magnus::{
current_receiver, define_global_function, method, prelude::*, rb_assert, Error, Value,
};
fn example(rb_self: Value) -> Result<bool, Error> {
rb_self.equal(current_receiver::<Value>()?)
}
define_global_function("example", method!(example, 0));
rb_assert!("example");