Sha256: 2e639d54125c207dca3faf2131e7574d02990164787165df05ce817bddfcc4de
Contents?: true
Size: 1.98 KB
Versions: 1
Compression:
Stored size: 1.98 KB
Contents
module Domainic module Attributer # A module providing instance-level attribute functionality # # This module defines instance methods for objects that include {Domainic::Attributer}. # It provides initialization handling and attribute serialization capabilities, making # it easy to work with attribute values in a consistent way # # @example Basic usage # class Person # include Domainic::Attributer # # argument :name # option :age, default: nil # option :role, default: 'user', private_read: true # end # # person = Person.new('Alice', age: 30) # person.to_h # => { name: 'Alice', age: 30 } # role is private, not included # # @author {https://aaronmallen.me Aaron Allen} # @since 0.1.0 module InstanceMethods # Initialize a new instance with attribute values # # Handles both positional arguments and keyword options, applying them to their # corresponding attributes. This process includes: # 1. Validating required arguments # 2. Applying default values # 3. Type validation and coercion # 4. Change notifications # # @example # person = Person.new('Alice', age: 30) # # @raise [ArgumentError] if required arguments are missing # @return [InstanceMethods] the new InstanceMethods instance def initialize: (*untyped arguments, **untyped keyword_arguments) -> void # Convert public attribute values to a hash # # Creates a hash containing all public readable attributes and their current values. # Any attributes marked as private or protected for reading are excluded from # the result # # @example # person = Person.new('Alice', age: 30) # person.to_h # => { name: 'Alice', age: 30 } # # @return [Hash{Symbol => Object}] hash of attribute names to values def to_hash: () -> Hash[Symbol, untyped] alias to_h to_hash end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
domainic-attributer-0.2.0 | sig/domainic/attributer/instance_methods.rbs |