A Ruby gem that reduces boilerplate code with methods like attr_initialize, pattr_initialize, and method_object.
attr_extras is a Ruby gem that provides additional attribute methods to reduce boilerplate code in class definitions. It offers shortcuts for creating initializers, private readers, value objects, and method objects, making it easier to write clean, focused classes without the downsides of using Struct. The gem helps developers extract small classes more freely by minimizing repetitive patterns.
Ruby developers who write object-oriented code and want to reduce boilerplate, especially those building applications with many small, focused classes or following patterns like service objects and value objects.
Developers choose attr_extras because it significantly cuts down on verbose initialization and attribute definition code while maintaining clarity and findability. Its explicit method names make code scanning easier, and it avoids the pitfalls of alternatives like Struct inheritance.
Takes some boilerplate out of Ruby with methods like attr_initialize.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Methods like pattr_initialize condense initialize and attr_reader lines into a single declaration, as shown in the README's InvoicePolicy and PayInvoice examples, cutting repetitive code significantly.
Explicit names such as attr_initialize and attr_value enhance code scanning and clarity, aligning with the library's philosophy of findability for maintainable Ruby code.
Direct facilitation of patterns like Method Object (method_object) and Value Object (attr_value) with automatic equality handling simplifies implementation of focused classes.
Supports positional and keyword arguments with validation for required keywords, reducing manual error-checking code, as detailed in the attr_initialize section.
By default, attr_extras adds methods to all Ruby classes, which can be intrusive for library developers and requires explicit mode with extra setup to confine.
Version 4.0.0 made a breaking change to method_object, shifting its behavior and potentially disrupting existing codebases without careful migration.
The library cannot be used with BasicObject subclasses due to dependencies on standard Object methods, limiting its utility in certain metaprogramming scenarios.
Default values for keyword arguments are evaluated at class load time, not per instance, which can lead to unexpected behavior and requires workarounds, as admitted in the README.