ruby-metaprogramming

Define dynamic methods and intercept missing methods in Ruby using metaprogramming constructs.

187|20|Updated Nov 20, 2025
One-click install
npx skills add https://github.com/TheBushidoCollective/han --skill ruby-metaprogramming
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ruby-metaprogramming
Source: https://github.com/TheBushidoCollective/han/tree/main/jutsu/jutsu-ruby/skills/ruby-metaprogramming
Command: npx skills add https://github.com/TheBushidoCollective/han --skill ruby-metaprogramming

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill covers Ruby metaprogramming techniques like dynamic method definitions, method_missing, and reflection.

Core Features & Use Cases

  • Dynamic Methods: Define methods at runtime.
  • Reflection: Inspect and modify objects and classes.
  • Singletons & Macros: Advanced metaprogramming patterns.

Quick Start

Create a dynamic attribute generator using define_method and a small reflection example.

Frequently Asked Questions about ruby-metaprogramming

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define methods dynamically at runtime in Ruby?

Dynamic method definition in Ruby uses define_method to create methods at runtime based on conditions or data. This enables flexible APIs where methods are generated rather than hardcoded, useful for attribute accessors, DSLs, and adapters that need method coverage without explicit declarations.

What is method_missing and when should I use it?

method_missing intercepts calls to undefined methods, allowing you to handle them dynamically. Use it to create flexible interfaces, proxy objects, or catch typos; it powers ORMs and APIs that forward unknown methods to underlying data structures without pre-defining every accessor.

How do I inspect and modify classes and objects in Ruby?

Reflection in Ruby lets you inspect object state, traverse class hierarchies, and modify behavior at runtime using methods like class, methods, instance_variables, and ancestors. This enables introspection-based frameworks, debugging tools, and metaprogramming that adapts code structure based on runtime discovery.

Can I evaluate code within a specific class or instance context?

class_eval, instance_eval, and module_eval execute code blocks within a target context, giving access to its methods and variables. This powers macros, DSLs, and configuration blocks where code runs as if it were defined inside the target, enabling powerful compile-time customization.

What are eigenclasses and singleton methods in Ruby?

Eigenclasses (singleton classes) hold methods unique to a single object or class. Define methods there to customize individual instances or add class methods without affecting the wider class hierarchy, useful for per-object behavior and advanced metaprogramming patterns.

When should I avoid metaprogramming in Ruby?

Avoid metaprogramming when simpler patterns suffice—it reduces readability and debugging difficulty. Heavy use of method_missing, const_missing, and dynamic eval complicates static analysis and team onboarding; prefer explicit methods unless runtime flexibility or scale genuinely demands it.