Function magnus::call_super
source · pub fn call_super<A, T>(args: A) -> Result<T, Error>where
A: ArgList,
T: TryConvert,
Expand description
Call the super method of the current method context.
Returns Ok(T)
if the super method exists and returns without error, and
the return value converts to a T
, or returns Err
if there is no super
method, the super method raises or the conversion fails.
§Panics
Panics if called from a non-Ruby thread. See Ruby::call_super
for the
non-panicking version.
§Examples
use magnus::{call_super, define_class, eval, function, prelude::*, rb_assert, Error};
let a = eval(
r#"
class A
def example
"Hello from A"
end
end
A
"#,
)
.unwrap();
let b = define_class("B", a).unwrap();
fn example() -> Result<String, Error> {
let s: String = call_super(())?;
Ok(format!("{}, and hello from B", s))
}
b.define_method("example", function!(example, 0)).unwrap();
rb_assert!(r#"B.new.example == "Hello from A, and hello from B""#)