Magnus bindings is an AI agent skill from the GitHub repository Goldziher/ai-rulez. Magnus Ruby extensions from a Rust core: define_class, TryConvert/IntoValue, exception mapping, GVL release, TypedData, rake-compiler builds. Use when writing or reviewing Magnus bindings.
Claude Code: save it as .claude/skills/magnus-bindings/SKILL.md
Cursor: save it as .cursor/rules/magnus-bindings.md
Codex: save it as .agents/skills/magnus-bindings/SKILL.md
ChatGPT, Gemini and other assistants: paste it into custom or project instructions
Skill file
Use magnus crate for Ruby native extensions. Define classes with magnus::define_class.
Map Rust types to Ruby using TryConvert and IntoValue traits. Return Result<T, magnus::Error>.
Use magnus::function! macro for defining Ruby methods. Use magnus::method! for instance methods.
Map Rust errors to specific Ruby exceptions: magnus::Error::new(exception::runtime_error(), msg).
Build with rb_sys crate and magnus-build for compilation. Use rake-compiler for gem distribution.
Support Ruby 3.2+ with multiple ABI versions.
Test bindings from Ruby using RSpec or Minitest. Test error handling and edge cases.
Keep Ruby wrapper gem thin — business logic in Rust, Ruby provides idiomatic API.
Handle Ruby's GVL (Global VM Lock) — release for CPU-intensive Rust code.
Use TypedData for wrapping Rust structs as Ruby objects with proper GC integration.
Anti-patterns: panics in Ruby methods, unsafe without SAFETY comments, manual memory management.
Use this skill with your AI agent:Open on Skill Issue to copy, download, or add to your library.
Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.