Cattri: The Ruby DSL for Clean, Scalable Class and Instance Attributes

GitHub: https://github.com/bnlucas/cattri Ruby gives us tools like attr_accessor, and Rails builds on this with class_attribute, cattr_accessor, and more—but if you’ve ever wrestled with their inconsistencies around visibility, subclassing, or defaults, you’re not alone. Cattri is a minimal-footprint Ruby DSL for defining both class- and instance-level attributes with clarity, safety, and control. Let's explore what makes it a better alternative. The Problem with Existing Attribute APIs Ruby’s attr_* respects visibility but doesn’t support class-level or subclass-safe behavior. Rails’ class_attribute handles subclassing but ignores visibility and requires ActiveSupport. If you're building a gem and want both, you’re forced to either duplicate logic manually or take on a heavyweight dependency. Feature/Behavior Cattri attr_* (Ruby) cattr_accessor (Rails) class_attribute (Rails)

Apr 23, 2025 - 02:57
 0
Cattri: The Ruby DSL for Clean, Scalable Class and Instance Attributes

GitHub: https://github.com/bnlucas/cattri

Ruby gives us tools like attr_accessor, and Rails builds on this with class_attribute, cattr_accessor, and more—but if you’ve ever wrestled with their inconsistencies around visibility, subclassing, or defaults, you’re not alone.

Cattri is a minimal-footprint Ruby DSL for defining both class- and instance-level attributes with clarity, safety, and control. Let's explore what makes it a better alternative.

The Problem with Existing Attribute APIs

Ruby’s attr_* respects visibility but doesn’t support class-level or subclass-safe behavior. Rails’ class_attribute handles subclassing but ignores visibility and requires ActiveSupport. If you're building a gem and want both, you’re forced to either duplicate logic manually or take on a heavyweight dependency.

Feature/Behavior Cattri attr_* (Ruby) cattr_accessor (Rails) class_attribute (Rails)

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies.