diff options
Diffstat (limited to 'lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt')
-rw-r--r-- | lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt b/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt new file mode 100644 index 0000000000..ba234529a3 --- /dev/null +++ b/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt @@ -0,0 +1,12 @@ +use magnus::{function, prelude::*, Error, Ruby}; + +fn hello(subject: String) -> String { + format!("Hello from Rust, {subject}!") +} + +#[magnus::init] +fn init(ruby: &Ruby) -> Result<(), Error> { + let module = ruby.<%= config[:constant_array].map {|c| "define_module(#{c.dump})?"}.join(".") %>; + module.define_singleton_method("hello", function!(hello, 1))?; + Ok(()) +} |