diff --git a/examples/complete_object/ext/temperature/src/lib.rs b/examples/complete_object/ext/temperature/src/lib.rs index 126b772c..3129deba 100644 --- a/examples/complete_object/ext/temperature/src/lib.rs +++ b/examples/complete_object/ext/temperature/src/lib.rs @@ -5,10 +5,10 @@ use std::{ }; use magnus::{ - class, define_class, exception, method, module, + method, prelude::*, scan_args::{get_kwargs, scan_args}, - typed_data, Error, Value, + typed_data, Error, Ruby, Value, }; #[magnus::wrap(class = "Temperature", free_immediately, size)] @@ -36,7 +36,11 @@ fn c_to_f(c: f64) -> f64 { } impl Temperature { - fn initialize(rb_self: typed_data::Obj, args: &[Value]) -> Result<(), Error> { + fn initialize( + ruby: &Ruby, + rb_self: typed_data::Obj, + args: &[Value], + ) -> Result<(), Error> { let args = scan_args::<(), (), (), (), _, ()>(args)?; let kwargs = get_kwargs::<_, (), (Option, Option, Option), ()>( args.keywords, @@ -49,13 +53,13 @@ impl Temperature { (None, None, Some(f)) => ((f_to_c(f) + C_OFFSET) * FACTOR) as u64, (None, None, None) => { return Err(Error::new( - exception::arg_error(), + ruby.exception_arg_error(), "missing keyword: :kelvin, :celsius, or :fahrenheit", )) } _ => { return Err(Error::new( - exception::arg_error(), + ruby.exception_arg_error(), "unexpected keyword, supply one of: :kelvin, :celsius, or :fahrenheit", )) } @@ -83,8 +87,8 @@ impl fmt::Display for Temperature { } #[magnus::init] -fn init() -> Result<(), Error> { - let class = define_class("Temperature", class::object())?; +fn init(ruby: &Ruby) -> Result<(), Error> { + let class = ruby.define_class("Temperature", ruby.class_object())?; // Define alloc func based on the Default impl, plus an initialize method, // rather than overwriting `new`, to allow class to be subclassed from Ruby @@ -113,7 +117,7 @@ fn init() -> Result<(), Error> { // <=> sort operator based on Rust PartialOrd impl class.define_method("<=>", method!(::cmp, 1))?; // defines <, <=, >, >=, and == based on <=> - class.include_module(module::comparable())?; + class.include_module(ruby.module_comparable())?; // debug/console output based on Rust Debug impl class.define_method( diff --git a/examples/custom_exception_ruby/ext/ahriman/src/lib.rs b/examples/custom_exception_ruby/ext/ahriman/src/lib.rs index 727c9e30..2eb0bf06 100644 --- a/examples/custom_exception_ruby/ext/ahriman/src/lib.rs +++ b/examples/custom_exception_ruby/ext/ahriman/src/lib.rs @@ -1,6 +1,6 @@ use magnus::{ - define_module, exception::ExceptionClass, function, gc::register_mark_object, prelude::*, - value::Lazy, Error, RModule, Ruby, + exception::ExceptionClass, function, gc::register_mark_object, prelude::*, value::Lazy, Error, + RModule, Ruby, }; static RUBRIC_ERROR: Lazy = Lazy::new(|ruby| { @@ -25,8 +25,8 @@ fn cast_rubric(ruby: &Ruby) -> Result<(), Error> { } #[magnus::init] -fn init() -> Result<(), Error> { - let module = define_module("Ahriman")?; +fn init(ruby: &Ruby) -> Result<(), Error> { + let module = ruby.define_module("Ahriman")?; module.define_singleton_method("cast_rubric", function!(cast_rubric, 0))?; Ok(()) } diff --git a/examples/rust_blank/ext/rust_blank/src/lib.rs b/examples/rust_blank/ext/rust_blank/src/lib.rs index 7ae1a4ef..26ba3927 100644 --- a/examples/rust_blank/ext/rust_blank/src/lib.rs +++ b/examples/rust_blank/ext/rust_blank/src/lib.rs @@ -1,10 +1,8 @@ use magnus::{ - class, - define_class, encoding::{CType, RbEncoding}, method, prelude::*, - Error, RString, + Error, RString, Ruby, }; fn is_blank(rb_self: RString) -> Result { @@ -38,8 +36,8 @@ fn is_blank(rb_self: RString) -> Result { } #[magnus::init] -fn init() -> Result<(), Error> { - let class = define_class("String", class::object())?; +fn init(ruby: &Ruby) -> Result<(), Error> { + let class = ruby.define_class("String", ruby.class_object())?; class.define_method("blank?", method!(is_blank, 0))?; Ok(()) }